/* fut_comp_itbl_ilut composes an input table with an 8-bit or 12-bit, * 256 entry look-up table. It returns a newly allocated table or NULL * if an error occurred. This is called by fut_comp_ilut() which in turn * is called by fut_comp_itbl(). * * Although we are recomputing the input table here, we do so by simply * rearranging an existing one (in case of an 8-bit lut) or by linearly * interpolating within an existing one (in the case of a 12-bit lut). * Therefore, there is no need to do any clipping to avoid referencing * off-grid values - provided, of course, that the existing input table * has been clipped (see note in fut_calc_itbl()). */ static fut_itbl_p fut_comp_itbl_ilut (fut_itbl_p itbl, KpChar_p lut, KpInt32_t is_12bits) { fut_itbl_p new_itbl; fut_itbldat_p idat; fut_itbldat_p new_idat; /* create a new input table */ new_itbl = fut_new_itblEx ((KpInt32_t)itbl->size, FUT_NULL_IFUNEX, NULL); if ( new_itbl == FUT_NULL_ITBL ) return (FUT_NULL_ITBL); /* assign a unique id since we are about to recompute */ new_itbl->id = fut_unique_id (); /* reorder the input table entries using the lut */ idat = itbl->tbl; new_idat = new_itbl->tbl; if ( is_12bits ) { /* since input tables are only 8 bits in, we must use the * lowest 4 bits of the 12 bit data to interpolate between the * input table entries specified by the highest 8 bits. */ KpInt16_p lut_p = (KpInt16_t FAR*) lut; KpInt16_p lut_end = lut_p + FUT_INPTBL_ENT; while ( lut_p < lut_end ) { *new_idat++ = fut_itbl_interp (idat,*lut_p); lut_p++; } } else { /* The lut is 8 bits so we simply do a table look up in the * input table to find the new entries. */ KpUInt8_p lut_p = (KpUInt8_t FAR*) lut; KpUInt8_p lut_end = lut_p + FUT_INPTBL_ENT; while ( lut_p < lut_end ) { *new_idat++ = idat[*lut_p++]; } } /* don't forget to set the very last (the 257th) input table entry */ *new_idat = *(new_idat-1); return (new_itbl); }
/* fut_new_chan allocates and initializes a fut_chan_t data structure. * If a required input table is missing, a ramp of the proper grid size * will be created. If a supplied itbl is not required, it will not be * inserted into the channel's private itbl list. All tables which are * actually used are copied and so the caller is responsible for * freeing the passed tables if necessary. * * If VARARGS is used, the list of input tables may be relaced by a * single array of fut_itbl_t pointers. This array must then be followed * by a fut_gtbl_p and a fut_otbl_p. */ fut_chan_p fut_new_chan ( KpInt32_t iomask, fut_itbl_p FAR* itbls, fut_gtbl_p gtbl, fut_otbl_p otbl) { fut_itbl_p itbl[FUT_NCHAN]; fut_chan_p chan; KpInt32_t imask, i, tIndex; /* get input mask */ imask = (KpInt32_t)FUT_IMASK(iomask); /* get args specified by imask */ for ( i=0, tIndex = 0; i<FUT_NCHAN; i++ ) { itbl[i] = ((imask & FUT_BIT(i)) && (itbls != NULL)) ? itbls[tIndex++] : NULL; } /* allocate and clear the fut_chan_t structure */ chan = fut_alloc_chan (); if ( ! IS_CHAN(chan)) { return (NULL); } /* check for valid grid and output tables */ if (( ! IS_GTBL(gtbl)) || ((otbl != NULL) && ( ! IS_OTBL(otbl))) ) { DIAG("fut_new_chan: invalid grid or output table.\n", 0); fut_free_chan (chan); return (NULL); } /* get required input channels from gtbl */ chan->imask = fut_gtbl_imask(gtbl); /* insert the required input tables */ for ( i=0; i<FUT_NICHAN; i++ ) { if ( (chan->imask & FUT_BIT(i)) == 0 ) continue; if ( itbl[i] == FUT_NULL_ITBL ) { chan->itbl[i] = fut_new_itblEx (KCP_REF_TABLES, KCP_FIXED_RANGE, gtbl->size[i], fut_irampEx, NULL); if ( chan->itbl[i] == NULL) { DIAG("fut_new_chan: can't create itbl.\n",0); fut_free_chan (chan); return (NULL); } chan->itblHandle[i] = chan->itbl[i]->handle; } else { if ( ! IS_ITBL (itbl[i])) { DIAG("fut_new_chan: invalid input table.\n", 0); fut_free_chan (chan); return (NULL); } else { if ( itbl[i]->size != gtbl->size[i] ) { DIAG("fut_new_chan: gtbl-itbl size mismatch.\n", 0); fut_free_chan (chan); return (NULL); } else { chan->itbl[i] = fut_share_itbl(itbl[i]); /* share the input table */ chan->itblHandle[i] = chan->itbl[i]->handle; } } } } /* insert grid and output tables */ chan->gtbl = fut_share_gtbl (gtbl); chan->gtblHandle = (IS_GTBL(chan->gtbl)) ? chan->gtbl->handle : FUT_NULL_HANDLE; if (IS_OTBL(otbl)) { chan->otbl = fut_share_otbl (otbl); } else { chan->otbl = fut_alloc_otbl(); } chan->otblHandle = (IS_OTBL(chan->otbl)) ? chan->otbl->handle : FUT_NULL_HANDLE; return (chan); }
fut_p constructfut ( KpInt32_t iomask, KpInt32_p sizeArray, fut_calcData_p fData, fut_ifunc_p ifunArray, fut_gfunc_p gfunArray, fut_ofunc_p ofunArray, PTDataClass_t iClass, PTDataClass_t oClass) { fut_p futp; KpInt32_t i1, imask, omask; fut_itbl_p itbls[FUT_NICHAN] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; fut_gtbl_p gtbls[FUT_NOCHAN] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; fut_otbl_p otbls[FUT_NOCHAN] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; fut_ifunc_t ifun; fut_gfunc_t gfun; fut_ofunc_t ofun; fData_t fDataL; fut_calcData_p fDataP; if (sizeArray == NULL) return NULL; if (fData == NULL) { fDataP = &fDataL.std; } else { fDataP = fData; } imask = FUT_IMASK(iomask); omask = FUT_OMASK(iomask); #if defined KCP_DIAG_LOG {KpChar_t string[256], str2[256]; KpInt32_t i1; sprintf (string, "constructfut\n iomask %x, sizeArray[]", iomask); for (i1 = 0; i1 < FUT_NICHAN; i1++) { if ((FUT_BIT(i1) & imask) != 0) { sprintf (str2, " %d", sizeArray[i1]); strcat (string, str2); } } sprintf (str2, ", fData %x, ifunArray %x, gfunArray %x, ofunArray %x, iClass %d, oClass %d\n", fData, ifunArray, gfunArray, ofunArray, iClass, oClass); strcat (string, str2); kcpDiagLog (string);} #endif /* Compute shared input tables: */ for (i1 = 0; i1 < FUT_NICHAN; i1++) { if ((imask & FUT_BIT(i1)) != 0) { if ((ifunArray == NULL) || (ifunArray[i1] == NULL)) { ifun = fut_irampEx; fDataP = &fDataL.std; if (iClass == KCP_VARIABLE_RANGE) { fDataL.scale = KCP_16_TO_8_ENCODING; } else { fDataL.scale = 1.0; } } else { ifun = ifunArray[i1]; } fDataP->chan = i1; /* define the channel # */ itbls[i1] = fut_new_itblEx (KCP_REF_TABLES, iClass, sizeArray[i1], ifun, fDataP); itbls[i1]->id = fut_unique_id (); itbls[i1]->dataClass = iClass; } } /* Compute grid tables and output tables: */ for (i1 = 0; i1 < FUT_NOCHAN; i1++) { if ((omask & FUT_BIT(i1)) != 0) { if ((gfunArray == NULL) || (gfunArray[i1] == NULL)) { gfun = fut_grampEx; } else { gfun = gfunArray[i1]; } fDataP->chan = i1; /* define the channel # */ gtbls[i1] = fut_new_gtblEx (KCP_REF_TABLES, iomask, gfun, fDataP, sizeArray); gtbls[i1]->id = fut_unique_id(); if ((ofunArray == NULL) || (ofunArray[i1] == NULL)) { ofun = fut_orampEx; fDataP = &fDataL.std; if (oClass == KCP_VARIABLE_RANGE) { fDataL.scale = KCP_8_TO_16_ENCODING; } else { fDataL.scale = 1.0; } } else { ofun = ofunArray[i1]; } otbls[i1] = fut_new_otblEx (KCP_REF_TABLES, oClass, ofun, fDataP); otbls[i1]->id = fut_unique_id(); otbls[i1]->dataClass = oClass; } } /* Assemble FuT: */ futp = fut_new (iomask, itbls, gtbls, otbls); fut_free_tbls (FUT_NICHAN, (KpGenericPtr_t *)itbls); fut_free_tbls (FUT_NOCHAN, (KpGenericPtr_t *)gtbls); fut_free_tbls (FUT_NOCHAN, (KpGenericPtr_t *)otbls); if (fut_to_mft (futp) != 1) { /* convert to reference tables */ fut_free (futp); futp = NULL; } return (futp); }