KpInt32_t TpGetDataSize ( KpHandle_t PTHdr, KpHandle_t PTData, PTType_t format) { KpInt32_t size, futRet, imask, omask, LUTDimensions, inputChans, outputChans; KpInt32_t i, tableSize, oTableEntries, gTableEntries, iTableEntries, nParaParams; PTErr_t errnum = KCP_INVAL_PTTYPE; fut_hdr_p futHdr; fut_p fut; KpUInt32_t lutConfig; size = 0; errnum = initExport (PTHdr, PTData, format, &futHdr, &fut); /* set up to export the data */ if (errnum == KCP_SUCCESS) { switch (format) { case PTTYPE_FUTF: size = fut_get_size (fut, futHdr); fut_free_tbldat (fut); /* free the made data tables */ break; case PTTYPE_MFT1: case PTTYPE_MFT2: case PTTYPE_MFT2_VER_0: futRet = fut_mfutInfo (fut, &LUTDimensions, &inputChans, &outputChans, format, &iTableEntries, &gTableEntries, &oTableEntries); if (futRet == 1) { size = inputChans * iTableEntries; /* total input table entries */ size += outputChans * (gTableEntries + oTableEntries); /* plus total grid and output table entries */ if (format == PTTYPE_MFT1) { size *= sizeof (mf1_tbldat_t); /* mult by bytes in each entry */ } else { size += 2; /* plus input and output table counters */ size *= sizeof (mf2_tbldat_t); /* mult by bytes in each entry */ } } fut_free_mftdat (fut); /* free the made data tables */ break; case PTTYPE_MAB1: case PTTYPE_MAB2: case PTTYPE_MBA1: case PTTYPE_MBA2: lutConfig = fut->lutConfig; /* input tables must be common and in first n contiguous input channels */ imask = fut->iomask.in; /* get the fut's input mask */ for (inputChans = 0; inputChans < FUT_NICHAN; inputChans++, imask >>= 1) { if ( ! IS_ITBL(fut->itbl[inputChans]) || ((imask & 1) == 0)) { break; } } if (imask != 0) { return (0); /* this fut can not be made into a matrix fut */ } /* output tables must be in first n contiguous output channels */ omask = fut->iomask.out; /* get the fut's output mask */ for (outputChans = 0; outputChans < FUT_NOCHAN; outputChans++, omask >>= 1) { if ( ! IS_CHAN(fut->chan[outputChans]) || ((omask & 1) == 0)) { break; } } if (omask != 0) { return (0); /* this fut can not be made into a matrix fut */ } tableSize = sizeof (mab_tbldat_t); if ((LUT_TYPE_UNKNOWN == lutConfig) || (MAB_B_CURVE_ONLY == lutConfig) || (MAB_A_CLUT_B_COMBO == lutConfig) || (MBA_B_CLUT_A_COMBO == lutConfig) || (MAB_A_CLUT_M_MATRIX_B_COMBO == lutConfig) || (MBA_B_MATRIX_M_CLUT_A_COMBO == lutConfig)) { for (i = 0; i < inputChans; i++) { if (PARA_TYPE_SIG == fut->itbl[i]->ParaCurve.nSig) { nParaParams = getNumParaParams(fut->itbl[i]->ParaCurve.nFunction); size += nParaParams * sizeof (Fixed_t) + CURVETYPE_HEADER; } else { iTableEntries = fut->itbl[i]->refTblEntries; size += (iTableEntries * tableSize) + CURVETYPE_HEADER; /* total input table entries */ } size = (size + 3) & ~3; } } if ((LUT_TYPE_UNKNOWN == lutConfig) || (MBA_B_CLUT_A_COMBO == lutConfig) || (MBA_B_MATRIX_M_CLUT_A_COMBO == lutConfig) || (MAB_A_CLUT_B_COMBO == lutConfig) || (MAB_A_CLUT_M_MATRIX_B_COMBO == lutConfig)) { gTableEntries = 0; for (i = 0; i < outputChans; i++) { gTableEntries += (fut->chan[0]->gtbl->tbl_size / sizeof (fut_gtbldat_t)); /* assume 8 bit grid tables */ } if ((PTTYPE_MAB2 == format) || (PTTYPE_MBA2 == format)) { gTableEntries *= 2; /* 16 bit grid tables */ } size += gTableEntries; size += CLUT_HEADER; size = (size + 3) & ~3; } if ((LUT_TYPE_UNKNOWN == lutConfig) || (MBA_B_CURVE_ONLY == lutConfig) || (MAB_A_CLUT_B_COMBO == lutConfig) || (MBA_B_CLUT_A_COMBO == lutConfig) || (MAB_A_CLUT_M_MATRIX_B_COMBO == lutConfig) || (MBA_B_MATRIX_M_CLUT_A_COMBO == lutConfig)) { for (i = 0; i < outputChans; i++) { if (PARA_TYPE_SIG == fut->chan[i]->otbl->ParaCurve.nSig) { nParaParams = getNumParaParams(fut->chan[i]->otbl->ParaCurve.nFunction); size += nParaParams * sizeof (Fixed_t) + CURVETYPE_HEADER; } else { oTableEntries = fut->chan[i]->otbl->refTblEntries; size += (oTableEntries * tableSize + CURVETYPE_HEADER); /* plus total output table entries */ } size = (size + 3) & ~3; } } if ((MBA_B_MATRIX_M_CLUT_A_COMBO == lutConfig) || (MBA_B_MATRIX_M_COMBO == lutConfig) || (MAB_M_MATRIX_B_COMBO == lutConfig)) { for (i = 0; i < FUT_NMCHAN; i++) { if (PARA_TYPE_SIG == fut->mabInParaCurve[i].nSig) { nParaParams = getNumParaParams(fut->mabInParaCurve[i].nFunction); size += nParaParams * sizeof (Fixed_t) + CURVETYPE_HEADER; } else { iTableEntries = fut->mabInTblEntries[i]; size += (iTableEntries * tableSize) + CURVETYPE_HEADER; /* plus total matrix inputput table entries */ } size = (size + 3) & ~3; } } if ((MAB_A_CLUT_M_MATRIX_B_COMBO == lutConfig) || (MBA_B_MATRIX_M_COMBO == lutConfig) || (MAB_M_MATRIX_B_COMBO == lutConfig)) { for (i = 0; i < FUT_NMCHAN; i++) { if (PARA_TYPE_SIG == fut->mabOutParaCurve[i].nSig) { nParaParams = getNumParaParams(fut->mabOutParaCurve[i].nFunction); size += nParaParams * sizeof (Fixed_t) + CURVETYPE_HEADER; } else { oTableEntries = fut->mabOutTblEntries[i]; size += (oTableEntries * tableSize) + CURVETYPE_HEADER; /* plus total matrix outputput table entries */ } size = (size + 3) & ~3; } } fut_free_mftdat (fut); /* free the made data tables */ break; default: break; } errnum = unlockPT (PTHdr, fut); if (errnum != KCP_SUCCESS) { size = 0; } } return (size); }
/* gridDimValid determines whether the grid table dimensions are valid * for the format specified. If the dimensions are not valid then the * function attempts to create a * PT with the correct size grid tables. If it is successful the * PTRefNum of the resized PT is returned in the location pointed to by * resizePTRefNumP. If resizing is not required the value returned in * the location pointed to by resizePTRefNumP is 0. * * NOTE: If this function creates a resized PT, that PT is checked in. * it is the responsibility of the calling function to check out * that PT. */ static PTErr_t gridDimValid ( PTType_t format, PTRefNum_t PTRefNum, PTRefNum_p resizePTRefNumP) { KpHandle_t PTData; KpInt32_t inputChans, outputChans, LUTDimensions, dummy = 0; fut_p fut; PTErr_t retVal, error = KCP_SUCCESS; /* Assume no resizing */ if (NULL != resizePTRefNumP) { *resizePTRefNumP = 0; } /* Convert the PTRefNum to a fut */ PTData = getPTData (PTRefNum); fut = fut_lock_fut (PTData); if (fut == FUT_NULL) { return KCP_PTERR_2; } if ( ! IS_FUT (fut) ) { /* check for valid fut */ retVal = KCP_NOT_FUT; goto GetOut; } switch (format ) { #if !defined KCP_ICC_ONLY case PTTYPE_FUTF: /* may want to check if any of the grid dimensions exceed the max grid dimension, but for now accept any size */ break; #endif case PTTYPE_MAB1: case PTTYPE_MAB2: case PTTYPE_MBA1: case PTTYPE_MBA2: /* may want to check if any of the grid dimensions exceed the max grid dimension, but for now accept any size */ break; case PTTYPE_MFT1: case PTTYPE_MFT2: case PTTYPE_MFT2_VER_0: /* The grid dimensions must all be the same. If they are not then attempt to build a grid table where all the dimensions are the same. */ retVal = (PTErr_t) fut_mfutInfo (fut, &LUTDimensions, &inputChans, &outputChans, format, &dummy, &dummy, &dummy); if (1 != retVal) { if (-2 != retVal) { retVal = KCP_INVAL_GRID_DIM; goto GetOut; } else { KpInt32_t i1, newGridDims[FUT_NICHAN]; fut_p futresized; for (i1 = 0; i1 < FUT_NICHAN; i1++) { /* define new grid sizes */ newGridDims[i1] = LUTDimensions; } futresized = fut_resize (fut, newGridDims); /* resize the fut */ if (futresized == NULL) { retVal = KCP_NO_MEMORY; goto GetOut; } if (futresized == fut) { /* should not happen, probably fut_mfutInfo() error */ retVal = KCP_SYSERR_3; goto GetOut; } if (fut_to_mft (futresized) != 1) { /* convert to reference tables */ retVal = KCP_INCON_PT; goto GetOut; } retVal = fut2PT (&futresized, -1, -1, PTTYPE_CALCULATED, resizePTRefNumP); /* make into PT */ if (retVal == KCP_SUCCESS) { retVal = copyAllAttr (PTRefNum, *resizePTRefNumP); /* Copy all attributes to new PT */ if (retVal != KCP_SUCCESS) { PTCheckOut (*resizePTRefNumP); goto GetOut; } } } } break; default: retVal = KCP_INVAL_PTTYPE; } retVal = KCP_SUCCESS; GetOut: fut_unlock_fut (fut); return retVal; }