/* TpReadData reads a fut from a memory block and returns a handle to a newly allocated fut */ PTErr_t TpReadData( KpFd_p fd, PTType_t format, PTRefNum_t PTRefNum, KpHandle_t PTHdr, KpHandle_t FAR* PTData) { PTErr_t errnum; fut_p fut = NULL, theFutFromMatrix = NULL, newFut = NULL, lab2xyzFut = NULL, finalFut = NULL; fut_hdr_p futHdr; Fixed_t matrix[MF_MATRIX_DIM * MF_MATRIX_DIM + MF_MATRIX_DIM]; KpInt32_t ret, iomask; KpChar_t ENUM_String[20]; KpInt32_t inCS, i, i1; ResponseRecord_t inRedTRC, inGreenTRC, inBlueTRC; ResponseRecord_t outRedTRC, outGreenTRC, outBlueTRC; PTRefNum_t matrixPTRefNum; PTDataClass_t iClass, oClass; futHdr = (fut_hdr_p) lockBuffer (PTHdr); /* get buffer pointer */ if (futHdr == NULL) { errnum = KCP_MEM_LOCK_ERR; goto GetOut; } futHdr->profileType = getIntAttrDef (PTRefNum, KCM_ICC_PROFILE_TYPE); futHdr->spaceIn = getIntAttrDef (PTRefNum, KCM_SPACE_IN); futHdr->spaceOut = getIntAttrDef (PTRefNum, KCM_SPACE_OUT); futHdr->iDataClass = getDataClass (futHdr->spaceIn); futHdr->oDataClass = getDataClass (futHdr->spaceOut); switch (format) { case FUT_CIGAM: /* fut with bytes reversed */ case FUT_MAGIC: /* fut with bytes in correct order */ if ((fut = fut_alloc_fut ()) == NULL) { /* allocate a new fut structure */ errnum = KCP_NO_ACTIVATE_MEM; } else { if (fut_read_tbls (fd, fut, futHdr) != 1) { /* read fut tables */ errnum = KCP_PT_DATA_READ_ERR; } else { if (fut_io_decode (fut, futHdr) == 0) { errnum = KCP_PTERR_0; } else { errnum = KCP_SUCCESS; } } } break; case PTTYPE_MFT1: case PTTYPE_MFT2: fut = fut_readMFutTbls (fd, futHdr, matrix); /* read matrix fut tables */ if (fut == NULL) { errnum = KCP_NO_ACTIVATE_MEM; } else { inCS = getIntAttrDef (PTRefNum, KCM_SPACE_IN); if ((inCS == KCM_CIE_XYZ) && (isIdentityMatrix (matrix, MF_MATRIX_DIM) != 1)) { ret = makeOutputMatrixXform ((Fixed_p)&matrix, 8, &theFutFromMatrix); if (ret != 1) { errnum = KCP_INCON_PT; goto GetOut; } else { iomask = FUT_PASS(FUT_XYZ); /* get the Lab to XYZ fut */ lab2xyzFut = get_lab2xyz (KCP_GRID_DIM_SIXTEEN); newFut = fut_comp (theFutFromMatrix, lab2xyzFut, iomask); if (newFut != NULL) { finalFut = fut_comp (fut, newFut, iomask); } fut_free (theFutFromMatrix); /* free intermediate futs */ fut_free (lab2xyzFut); fut_free (fut); fut_free (newFut); fut = finalFut; /* set the input color space attribute to Lab */ KpItoa (KCM_CIE_LAB, ENUM_String); errnum = PTSetAttribute (PTRefNum, KCM_SPACE_IN, ENUM_String); if (errnum != KCP_SUCCESS) { goto GetOut; } /* set the input composition attribute to Lab */ errnum = PTSetAttribute (PTRefNum, KCM_IN_CHAIN_CLASS_2, "6"); if (errnum != KCP_SUCCESS) { goto GetOut; } } } if ((fut == NULL) || !fut_io_encode (fut, futHdr)) { /* make the info header */ errnum = KCP_INCON_PT; goto GetOut; } errnum = KCP_SUCCESS; } break; case PTTYPE_MA2B: case PTTYPE_MB2A: matrix[0] = matrix[4] = matrix[8] = KpF15d16FromDouble(1.0); matrix[1] = matrix[2] = matrix[3] = matrix[5] = matrix[6] = matrix[7] = matrix[9] = matrix[10] = matrix[11] = KpF15d16FromDouble(0.0); fut = fut_readMabFutTbls (fd, futHdr, matrix); /* read matrix fut tables */ if (fut == NULL) { errnum = KCP_NO_ACTIVATE_MEM; } else { if (fut->lutConfig & HAS_MATRIX_DATA) { i = MF_MATRIX_DIM * MF_MATRIX_DIM + MF_MATRIX_DIM; for (i1 = 0; i1 < i; i1++) { fut->matrix[i1] = matrix[i1]; } switch (fut->lutConfig) { case MAB_M_MATRIX_B_COMBO: case MBA_B_MATRIX_M_COMBO: inRedTRC.CurveCount = fut->mabInTblEntries[0]; inGreenTRC.CurveCount = fut->mabInTblEntries[1]; inBlueTRC.CurveCount = fut->mabInTblEntries[2]; inRedTRC.CurveData = fut->mabInRefTbl[0]; inGreenTRC.CurveData = fut->mabInRefTbl[1]; inBlueTRC.CurveData = fut->mabInRefTbl[2]; outRedTRC.CurveCount = fut->mabOutTblEntries[0]; outGreenTRC.CurveCount = fut->mabOutTblEntries[1]; outBlueTRC.CurveCount = fut->mabOutTblEntries[2]; outRedTRC.CurveData = fut->mabOutRefTbl[0]; outGreenTRC.CurveData = fut->mabOutRefTbl[1]; outBlueTRC.CurveData = fut->mabOutRefTbl[2]; iClass = getDataClass(futHdr->spaceIn); oClass = getDataClass(futHdr->spaceOut); ret = makeFutFromMatrix ((Fixed_p)&matrix, &inRedTRC, &inGreenTRC, &inBlueTRC, &outRedTRC, &outGreenTRC, &outBlueTRC, MATRIX_GRID_SIZE, iClass, oClass, (fut_p *)&theFutFromMatrix); break; case MBA_B_MATRIX_M_CLUT_A_COMBO: inRedTRC.CurveCount = fut->mabInTblEntries[0]; inGreenTRC.CurveCount = fut->mabInTblEntries[1]; inBlueTRC.CurveCount = fut->mabInTblEntries[2]; inRedTRC.CurveData = fut->mabInRefTbl[0]; inGreenTRC.CurveData = fut->mabInRefTbl[1]; inBlueTRC.CurveData = fut->mabInRefTbl[2]; iClass = getDataClass(futHdr->spaceIn); oClass = KCP_UNKNOWN; ret = makeFutFromMatrix ((Fixed_p)&matrix, &inRedTRC, &inGreenTRC, &inBlueTRC, NULL, NULL, NULL, MATRIX_GRID_SIZE, iClass, oClass, (fut_p *)&theFutFromMatrix); break; case MAB_A_CLUT_M_MATRIX_B_COMBO: outRedTRC.CurveCount = fut->mabOutTblEntries[0]; outGreenTRC.CurveCount = fut->mabOutTblEntries[1]; outBlueTRC.CurveCount = fut->mabOutTblEntries[2]; outRedTRC.CurveData = fut->mabOutRefTbl[0]; outGreenTRC.CurveData = fut->mabOutRefTbl[1]; outBlueTRC.CurveData = fut->mabOutRefTbl[2]; iClass = KCP_UNKNOWN; oClass = getDataClass(futHdr->spaceOut); ret = makeFutFromMatrix ((Fixed_p)&matrix, NULL, NULL, NULL, &outRedTRC, &outGreenTRC, &outBlueTRC, MATRIX_GRID_SIZE, iClass, oClass, (fut_p *)&theFutFromMatrix); break; default: break; } if (NULL != theFutFromMatrix) { /* Create a PT from the fut */ errnum = fut2PT (&theFutFromMatrix, KCM_UNKNOWN, KCM_UNKNOWN, PTTYPE_CALCULATED, &matrixPTRefNum); if (errnum != KCP_SUCCESS) { goto GetOut; } errnum = setMatrixPTRefNum (PTRefNum, matrixPTRefNum, fut->lutConfig); if (errnum != KCP_SUCCESS) { goto GetOut; } } if (ret != 1) { errnum = KCP_INCON_PT; goto GetOut; } } if ((fut == NULL) || !fut_io_encode (fut, futHdr)) { /* make the info header */ errnum = KCP_INCON_PT; goto GetOut; } errnum = KCP_SUCCESS; } break; default: break; } GetOut: if ((errnum != KCP_SUCCESS) || (fut == NULL)) { fut_free (fut); } else { /* return handle to fut to caller */ /* make sure the futs are in the reference state */ if (fut_to_mft (fut) == 1) { *PTData = (KpHandle_t)fut_unlock_fut (fut); } } if ( ! unlockBuffer (PTHdr)) { errnum = KCP_MEM_UNLOCK_ERR; } return errnum; }
fut_p fut_resize ( fut_p fut, KpInt32_p sizeArray) { fut_p reSizedGtblFut = NULL, gtblFut = NULL, reSizedFut = NULL, identityFut = NULL; KpInt32_t i1, i2, iomask, iiomask, imask, omask, sameDims; fut_chan_p chan; fut_itbl_p itbl, itbls[FUT_NICHAN]; fut_gtbl_p gtbls[FUT_NOCHAN]; fut_otbl_p otbls[FUT_NOCHAN]; #if defined KCP_DIAG_LOG kcpDiagLog ("fut_resize\n"); #endif if ( ! IS_FUT(fut)) { return NULL; } for (i1 = 0; i1 < FUT_NICHAN; i1++) { itbls[i1] = FUT_NULL_ITBL; /* init to null for freeing on error */ } /* collect the gtbls from the source fut */ /* make sure that all the gtbls use the same itbls */ omask = 0; for (i1 = 0, sameDims = 1; i1 < FUT_NOCHAN; i1++) { chan = fut->chan[i1]; if (IS_CHAN(chan)) { for (i2 = 0; i2 < FUT_NICHAN; i2++) { itbl = fut->itbl[i2]; if (chan->itbl[i2] != itbl) { /* must be shared */ goto GetOut; } if (IS_ITBL(itbl)) { if (itbl->size != sizeArray [i2]) { sameDims = 0; /* not the same */ } } } omask |= FUT_BIT(i1); /* resize this chan */ gtbls[i1] = chan->gtbl; /* collect gtbls */ } else { gtbls[i1] = NULL; } } if (sameDims == 1) { return fut; /* already the right size! */ } imask = fut->iomask.in; iomask = FUT_OUT(omask) | FUT_IN(imask); /* make a new fut with these gtbls and identity itbls and otbls */ gtblFut = fut_new (iomask, NULL, gtbls, NULL); if (gtblFut != NULL) { /* make an identity fut with itbls that have the specified sizes */ iiomask = FUT_OUT(imask) | FUT_IN(imask); identityFut = constructfut (iiomask, sizeArray, NULL, NULL, NULL, NULL, KCP_FIXED_RANGE, KCP_FIXED_RANGE); if (identityFut != NULL) { /* compose the new size fut with the gtbl fut */ reSizedGtblFut = fut_comp (gtblFut, identityFut, 0); if (reSizedGtblFut != NULL) { /* make a new fut with original itbls, ... */ for (i1 = 0; i1 < FUT_NICHAN; i1++) { if ((imask & FUT_BIT(i1)) != 0) { itbls[i1] = fut_copy_itbl (fut->itbl[i1]); /* copy (do not share!) original itbls */ if (itbls[i1] == NULL) { goto GetOut; } makeMftiTblDat (itbls[i1]); /* convert to mft to remove grid size dependancy */ itbls[i1]->size = reSizedGtblFut->itbl[i1]->size; /* set new grid size */ fut_free_itbldat (itbls[i1], freeData); /* free fixed table, it has incorrect grid indices */ } } /* ... resized gtbls, and original otbls */ for (i1 = 0; i1 < FUT_NOCHAN; i1++) { if ((omask & FUT_BIT(i1)) != 0) { gtbls[i1] = reSizedGtblFut->chan[i1]->gtbl; /* collect resized gtbls */ otbls[i1] = fut->chan[i1]->otbl; /* and original otbls */ } else { gtbls[i1] = NULL; otbls[i1] = NULL; } } reSizedFut = fut_new (iomask, itbls, gtbls, otbls); } } } GetOut: fut_free (reSizedGtblFut); /* free the intermediate futs */ fut_free (gtblFut); fut_free (identityFut); fut_free_tbls (FUT_NICHAN, (void **)itbls); return (reSizedFut); }