/* abort the current PT chaining function */ void clearChain ( chainState_p cS) { PTCheckOut (cS->currentPT); /* free the current PT */ KpMemSet (cS, 0, sizeof (chainState_t)); /* no chaining active */ KpThreadMemDestroy (&theRootID, KPTHREADMEM); }
/* getPTFromFile * * This routine is used when the uvL/LAB conversion PTs are * read from a file versus being generated by sprofile * * Only PTs are supported by this routine. */ KpInt32_t getPTFromFile(SpDirection_t direction, KpInt32_t Render, PTRefNum_t *thePT) { KpMapFile_t mappedFile; KpFileProps_t props; KpChar_p file; if (direction == SpDir2LAB) file = uvl2labName; else { switch (Render) { case KCM_COLORIMETRIC: file = lab2uvlCName; break; case KCM_SATURATION_MATCH: file = lab2uvlSName; break; case KCM_PERCEPTUAL: default: file = lab2uvlPName; break; } } if( !KpMapFileEx(file,&props,"r",&mappedFile) ) return -1; if( PTCheckIn(thePT,mappedFile.Ptr) != KCP_SUCCESS ) { KpUnMapFile(&mappedFile); return -1; } if( PTActivate(*thePT,mappedFile.NumBytes,mappedFile.Ptr) != KCP_SUCCESS ) { KpUnMapFile(&mappedFile); PTCheckOut( *thePT ); return -1; } KpUnMapFile(&mappedFile); return 0; }
/*-------------------------------------------------------------------- * DESCRIPTION * Generate Colorant and Response Curve tags for the specified * Xform data. This data is assumed to be a PT. * * AUTHOR * lsh * * DATE CREATED * April 15, 1994 *------------------------------------------------------------------*/ SpStatus_t KSPAPI SpXformCreateMatTags ( SpProfile_t Profile, KpInt32_t DataSize, KpLargeBuffer_t Data) { SpStatus_t Status; PTRefNum_t RefNum; SpHeader_t Hdr; KpInt32_t SpDataType; Status = SpProfileGetHeader (Profile, &Hdr); if (SpStatSuccess != Status) return Status; if ((Hdr.Originator == SpSigOrgKodak1_Ver_0) || (Hdr.Originator == SpSigOrgKodak2_Ver_0)) { SpDataType = KCM_ICC_TYPE_0; } else { SpDataType = KCM_ICC_TYPE_1; } #if defined KCP_DIAG_LOG {KpChar_t string[256]; sprintf (string, "\nSpXformCreateMatTags\n Profile %x, DataSize %d, Data %x\n", Profile, DataSize, Data); kcpDiagLog (string); } #endif Status = SpXformLoadImp (Data, DataSize, SpDataType, Hdr.DataColorSpace, Hdr.InterchangeColorSpace, &RefNum); if (SpStatSuccess != Status) return Status; Status = SpXformCreateMatTagsFromPT (Profile, RefNum); PTCheckOut (RefNum); return Status; }
/*-------------------------------------------------------------------- * DESCRIPTION * Create a duplicate of an existing transform. * * AUTHOR * gbp * * DATE Modified * 25 Jan 99 *------------------------------------------------------------------*/ SpStatus_t KSPAPI SpXformDuplicate ( SpXform_t srcXform, SpXform_t FAR *dupXform) { SpStatus_t Status; PTRefNum_t srcRefNum, dupRefNum; PTErr_t PTStat; *dupXform = NULL; /* Get the PTRefNum for the transform */ Status = SpXformGetRefNum (srcXform, &srcRefNum); if (SpStatSuccess != Status) { return Status; } /* duplicate it by using PTCombine */ PTStat = PTCombine (0, srcRefNum, NULL, &dupRefNum); if (KCP_SUCCESS != PTStat) { return (SpStatusFromPTErr(PTStat)); } /* build an SpXform_t from the RefNum */ if (SpStatSuccess == Status) Status = SpXformFromPTRefNumImp (dupRefNum, dupXform); /* free PT if SpXform_t not created */ if (SpStatSuccess != Status) PTCheckOut (dupRefNum); #if defined KCP_DIAG_LOG {KpChar_t string[256]; sprintf (string, "\nSpXformFromBufferDT\n *dupXform %x\n",*dupXform); kcpDiagLog (string); } #endif return Status; }
PTErr_t PTNewMonoPT ( ResponseRecord_p grayTRC, KpUInt32_t gridsize, KpBool_t invert, PTRefNum_p thePTRefNumP) { PTErr_t PTErr; KpInt32_t dim[3], inSpace, outSpace; fut_p theFut = NULL; /* Check for valid ptrs */ PTErr = KCP_BAD_ARG; if (thePTRefNumP == NULL) goto GetOut; if (grayTRC == NULL) goto GetOut; if (gridsize < 2) goto GetOut; *thePTRefNumP = 0; /* all dimensions are the same */ dim[0] = dim[1] = dim[2] = (KpInt32_t) gridsize; /* pass the input arguments along to the fut maker */ if (invert == KPFALSE) { /* Create (1D -> 3D) FuT */ theFut = fut_new_empty (1, dim, 3, KCP_FIXED_RANGE, KCP_LAB_PCS); if (theFut == NULL) { goto ErrOut4; } PTErr = makeForwardXformMono (grayTRC, theFut); inSpace = KCM_MONO; /* setup the foward color space */ outSpace = KCM_CIE_LAB; } else { /* Create (3D -> 1D) FuT */ theFut = fut_new_empty (3, dim, 1, KCP_LAB_PCS, KCP_FIXED_RANGE); if (theFut == NULL) { goto ErrOut4; } PTErr = makeInverseXformMono (grayTRC, theFut); inSpace = KCM_CIE_LAB; /* setup the inverse color space */ outSpace = KCM_MONO; } if (PTErr != KCP_SUCCESS) { goto ErrOut1; } if (fut_to_mft (theFut) != 1) { /* convert to reference tables */ goto ErrOut3; } PTErr = fut2PT (&theFut, inSpace, outSpace, PTTYPE_CALCULATED, thePTRefNumP); /* make into PT */ if (PTErr != KCP_SUCCESS) { goto ErrOut0; } GetOut: return (PTErr); ErrOut4: PTErr = KCP_NO_MEMORY; goto ErrOut0; ErrOut3: PTErr = KCP_INCON_PT; goto ErrOut0; ErrOut1: PTErr = KCP_BAD_ARG; ErrOut0: if (theFut != NULL) fut_free (theFut); if (*thePTRefNumP != 0) PTCheckOut (*thePTRefNumP); goto GetOut; }
/*------------------------------------------------------------------------------ * PTGetRelToAbsPT -- generate a PT which converts from ICC relative colorimetry to ICC absolute colorimetry (absolute color) = ((media white point) / (profile white point)) * (relative color) so (source absolute color) = ((source media white point) / (source profile white point)) * (source relative color) and (dest absolute color) = ((dest media white point) / (dest profile white point)) * (dest relative color) equating source and dest absolute colors (dest relative color) = ((source media white point) / (dest media white point)) * ((dest profile white point) / (source profile white point)) * (source relative color) *------------------------------------------------------------------------------ */ PTErr_t PTGetRelToAbsPT( KpUInt32_t RelToAbsMode, PTRelToAbs_p PTRelToAbs, PTRefNum_p PTRefNumPtr) { PTErr_t PTErr; KpInt32_t status; FloatXYZColor_t sMWP, dMWP, sPWP, dPWP; Fixed_t matrix[MF_MATRIX_DIM * MF_MATRIX_DIM]; fut_p theFutFromMatrix = NULL; /* just one mode now. allows for future expansion of the function */ if (RelToAbsMode != 0) return KCP_NOT_IMPLEMENTED; if (PTRefNumPtr == NULL) return KCP_BAD_ARG; *PTRefNumPtr = 0; sMWP.X = PTRelToAbs->srcMediaWhitePoint.X / (KpFloat32_t)KpF15d16Scale; /* convert fixed point XYZ to floating point */ sMWP.Y = PTRelToAbs->srcMediaWhitePoint.Y / (KpFloat32_t)KpF15d16Scale; sMWP.Z = PTRelToAbs->srcMediaWhitePoint.Z / (KpFloat32_t)KpF15d16Scale; dMWP.X = PTRelToAbs->dstMediaWhitePoint.X / (KpFloat32_t)KpF15d16Scale; dMWP.Y = PTRelToAbs->dstMediaWhitePoint.Y / (KpFloat32_t)KpF15d16Scale; dMWP.Z = PTRelToAbs->dstMediaWhitePoint.Z / (KpFloat32_t)KpF15d16Scale; sPWP.X = PTRelToAbs->srcProfileWhitePoint.X / (KpFloat32_t)KpF15d16Scale; sPWP.Y = PTRelToAbs->srcProfileWhitePoint.Y / (KpFloat32_t)KpF15d16Scale; sPWP.Z = PTRelToAbs->srcProfileWhitePoint.Z / (KpFloat32_t)KpF15d16Scale; dPWP.X = PTRelToAbs->dstProfileWhitePoint.X / (KpFloat32_t)KpF15d16Scale; dPWP.Y = PTRelToAbs->dstProfileWhitePoint.Y / (KpFloat32_t)KpF15d16Scale; dPWP.Z = PTRelToAbs->dstProfileWhitePoint.Z / (KpFloat32_t)KpF15d16Scale; matrix[0] = (Fixed_t)(((sMWP.X * dPWP.X) / (dMWP.X * sPWP.X) * KpF15d16Scale) + 0.5); /* fill in the matrix */ matrix[1] = 0; matrix[2] = 0; matrix[3] = 0; matrix[4] = (Fixed_t)(((sMWP.Y * dPWP.Y) / (dMWP.Y * sPWP.Y) * KpF15d16Scale) + 0.5); matrix[5] = 0; matrix[6] = 0; matrix[7] = 0; matrix[8] = (Fixed_t)(((sMWP.Z * dPWP.Z) / (dMWP.Z * sPWP.Z) * KpF15d16Scale) + 0.5); status = makeOutputMatrixXform ((Fixed_p)&matrix, PTRelToAbs->gridSize, &theFutFromMatrix); if (status != 1) { goto ErrOut1; } if (fut_to_mft (theFutFromMatrix) != 1) { /* convert to reference tables */ goto ErrOut3; } PTErr = fut2PT (&theFutFromMatrix, KCM_CIE_XYZ, KCM_CIE_XYZ, PTTYPE_CALCULATED, PTRefNumPtr); /* make into PT */ if (PTErr != KCP_SUCCESS) { goto ErrOut0; } GetOut: return (PTErr); ErrOut3: PTErr = KCP_INCON_PT; goto ErrOut0; ErrOut1: PTErr = KCP_BAD_ARG; ErrOut0: if (theFutFromMatrix != NULL) fut_free (theFutFromMatrix); if (*PTRefNumPtr != 0) PTCheckOut (*PTRefNumPtr); goto GetOut; }
PTErr_t PTChain ( PTRefNum_t PTRefNum) { chainState_p cS; PTErr_t PTErr, PTErr1; KpHandle_t PTData; PTRefNum_t PTRefNum1 = NULL, PTRefNum2 = NULL; KpInt32_t mode; fut_p fut = NULL; KpChar_t auxPTName[30]; PTErr = getChainState (&cS); if (PTErr != KCP_SUCCESS) return PTErr; if (cS->chainLength == 0) { PTErr = KCP_NO_CHAININIT; goto GetOut; } if (cS->chainIndex >= cS->chainLength) { PTErr = KCP_EXCESS_PTCHAIN; goto GetOut; } if (cS->chainDef[cS->chainIndex] != PTRefNum) { PTErr = KCP_INVAL_PT_SEQ; goto GetOut; } PTErr = PTGetPTInfo (PTRefNum, NULL, NULL, (PTAddr_p*)&PTData); if (PTErr != KCP_PT_ACTIVE) { goto GetOut; } mode = cS->compMode & PT_COMBINE_TYPE; if (cS->currentPT == 0) { /* first PT in chain? */ KpInt32_t srcFormat; srcFormat = PTGetSrcFormat (PTRefNum); /* get original format */ /* we hard coded this rule just for pts and not for profiles */ if ((srcFormat == PTTYPE_FUTF) && (cS->iComp == KCM_CHAIN_CLASS_CMYK)) { if (cS->oComp == KCM_CHAIN_CLASS_MON_RGB) { strcpy (auxPTName, "CP10i"); } else { strcpy (auxPTName, "CP05"); } PTErr = loadAuxPT (auxPTName, cS->inSense, &PTRefNum1); /* get the aux PT */ if (PTErr != KCP_SUCCESS) { goto GetOut; } PTRefNum2 = PTRefNum; } else { PTRefNum1 = PTRefNum; /* first PT in chain */ PTRefNum2 = NULL; } } else { KpInt32_t OutSpace, InSpace; OutSpace = getIntAttrDef (cS->currentPT, KCM_SPACE_OUT); InSpace = getIntAttrDef (PTRefNum, KCM_SPACE_IN); /* if the color spaces are not the same, and */ if ((OutSpace != InSpace) && /* neither color space is unknown, and */ (OutSpace != KCM_UNKNOWN) && (InSpace != KCM_UNKNOWN) && /* this is a profile composition, then */ ((mode == PT_COMBINE_PF_8) || (mode == PT_COMBINE_PF_16) || (mode == PT_COMBINE_PF)) && /* both color spaces must be ICC PCS */ (((OutSpace != KCM_CIE_LAB) && (OutSpace != KCM_CIE_XYZ)) || ((InSpace != KCM_CIE_LAB) && (InSpace != KCM_CIE_XYZ)))) { PTErr = KCP_OUTSPACE_INSPACE_ERR; /* that's not allowed */ goto GetOut; } PTRefNum1 = cS->currentPT; /* set up composition */ PTRefNum2 = PTRefNum; } /* finally, compose the PTs */ PTErr = PTCombine (cS->compMode, PTRefNum1, PTRefNum2, &cS->currentPT); if (PTRefNum1 != PTRefNum) { PTErr1 = PTCheckOut (PTRefNum1); /* free the internal PT */ if (PTErr1 != KCP_SUCCESS) { PTErr = PTErr1; /* return actual error */ goto GetOut; } } if (mode == PT_COMBINE_SERIAL) { makeSerial (cS->currentPT); /* it's a serial PT */ } cS->chainIndex++; /* next PT */ GetOut: if (PTErr == KCP_SUCCESS) { putChainState (cS); /* save chain state */ } else { clearChain (cS); /* abort PT chaining */ } return PTErr; }
/*-------------------------------------------------------------------- * DESCRIPTION * Construct Xform given a PT reference number. No RCS -> LAB color * space conversion is performed. * * AUTHOR * mjb * * DATE CREATED * September 27, 1995 *------------------------------------------------------------------*/ SpStatus_t KSPAPI SpXformFromPTRefNumNC ( PTRefNum_t FAR *RefNum, SpXform_t FAR *Xform) { KpInt32_t SpaceIn, SpaceOut; KpInt32_t SenseIn, SenseOut; KpInt32_t Class; int Index; SpStatus_t Status; PTErr_t InvertStat; Class = SpGetKcmAttrInt (*RefNum, KCM_CLASS); SpaceIn = SpGetKcmAttrInt (*RefNum, KCM_SPACE_IN); SpaceOut = SpGetKcmAttrInt (*RefNum, KCM_SPACE_OUT); SenseIn = SpGetKcmAttrInt (*RefNum, KCM_MEDIUM_SENSE_IN); SenseOut = SpGetKcmAttrInt (*RefNum, KCM_MEDIUM_SENSE_OUT); Index = 0; Status = SpStatSuccess; /* Invert input, if negative */ if ((KCM_RCS != SpaceIn) && (KCM_NEGATIVE == SenseIn)) { InvertStat = PTInvert (*RefNum, KCM_MEDIUM_SENSE_IN); if (InvertStat != KCP_SUCCESS) { PTCheckOut (*RefNum); *RefNum = 0; return SpStatusFromPTErr(InvertStat); } Status = SpSetKcmAttrInt (*RefNum, KCM_MEDIUM_SENSE_IN, KCM_POSITIVE); if (SpStatSuccess != Status) { PTCheckOut (*RefNum); *RefNum = 0; return Status; } } /* Invert output, if negative */ if ((KCM_RCS != SpaceOut) && (KCM_NEGATIVE == SenseOut)) { InvertStat = PTInvert (*RefNum, KCM_MEDIUM_SENSE_OUT); if (InvertStat != KCP_SUCCESS) { PTCheckOut (*RefNum); return SpStatusFromPTErr(InvertStat); } Status = SpSetKcmAttrInt (*RefNum, KCM_MEDIUM_SENSE_OUT, KCM_POSITIVE); if (SpStatSuccess != Status) { PTCheckOut (*RefNum); *RefNum = 0; return Status; } } Status = SpSetKcmAttrInt (*RefNum, KCM_CLASS, Class); if (SpStatSuccess != Status) { PTCheckOut (*RefNum); *RefNum = 0; return Status; } Status = SpXformFromPTRefNumImp (*RefNum, Xform); *RefNum = 0; return Status; }
/*-------------------------------------------------------------------- * DESCRIPTION * Construct Xform given a PT reference number. * FOR PT2PF building ONLY !! * * AUTHOR * lcc * * DATE CREATED * February 9, 1995 *------------------------------------------------------------------*/ SpStatus_t KSPAPI SpXformFromPTRefNumCombine ( SpConnectType_t ConnectType, SpParadigm_t ParadigmType, PTRefNum_t FAR *RefNum, SpXform_t FAR *Xform) { KpInt32_t SpaceIn, SpaceOut; KpInt32_t SenseIn, SenseOut; KpInt32_t Class, Render; int Index; KpInt32_t FailXform; SpStatus_t Status; PTRefNum_t CvrtInRefNum, CvrtOutRefNum; PTRefNum_t RefNumList [3]; PTRefNum_t NewRefNum; PTErr_t InvertStat; Class = SpGetKcmAttrInt (*RefNum, KCM_CLASS); SpaceIn = SpGetKcmAttrInt (*RefNum, KCM_SPACE_IN); SpaceOut = SpGetKcmAttrInt (*RefNum, KCM_SPACE_OUT); SenseIn = SpGetKcmAttrInt (*RefNum, KCM_MEDIUM_SENSE_IN); SenseOut = SpGetKcmAttrInt (*RefNum, KCM_MEDIUM_SENSE_OUT); /* setup to fix color spaces */ Index = 0; Status = SpStatSuccess; KpEnterCriticalSection (&SpCacheCritFlag); /* setup to fix input color space */ if (KCM_RCS == SpaceIn) { Render = SpGetKcmAttrInt (*RefNum, KCM_COMPRESSION_OUT); if (Render == KCM_UNKNOWN) Render = KCM_PERCEPTUAL; Status = SpXformBuildCnvrt (KPTRUE, Render, ConnectType, ParadigmType, &CvrtInRefNum); if (SpStatSuccess == Status) { RefNumList [Index++] = CvrtInRefNum; RefNumList [Index++] = *RefNum; } } else RefNumList [Index++] = *RefNum; /* setup to fix output color space */ if (KCM_RCS == SpaceOut) { Render = KCM_PERCEPTUAL; if (SpStatSuccess == Status) Status = SpXformBuildCnvrt (KPFALSE, Render, ConnectType, ParadigmType, &CvrtOutRefNum); if (SpStatSuccess == Status) RefNumList [Index++] = CvrtOutRefNum; } /* fix the color spaces */ if ((SpStatSuccess == Status) && (1 != Index)) { Status = SpConnectSequenceCombine (ConnectType, Index, RefNumList, &NewRefNum, &FailXform, NULL, NULL); PTCheckOut (*RefNum); *RefNum = NewRefNum; } KpLeaveCriticalSection (&SpCacheCritFlag); if (SpStatSuccess != Status) return Status; /* Invert input, if negative */ if ((KCM_RCS != SpaceIn) && (KCM_NEGATIVE == SenseIn)) { InvertStat = PTInvert (*RefNum, KCM_MEDIUM_SENSE_IN); if (InvertStat != KCP_SUCCESS) { PTCheckOut (*RefNum); return SpStatusFromPTErr(InvertStat); } Status = SpSetKcmAttrInt (*RefNum, KCM_MEDIUM_SENSE_IN, KCM_POSITIVE); if (SpStatSuccess != Status) { PTCheckOut (*RefNum); return Status; } } /* Invert output, if negative */ if ((KCM_RCS != SpaceOut) && (KCM_NEGATIVE == SenseOut)) { InvertStat = PTInvert (*RefNum, KCM_MEDIUM_SENSE_OUT); if (InvertStat != KCP_SUCCESS) { PTCheckOut (*RefNum); return SpStatusFromPTErr(InvertStat); } Status = SpSetKcmAttrInt (*RefNum, KCM_MEDIUM_SENSE_OUT, KCM_POSITIVE); if (SpStatSuccess != Status) { PTCheckOut (*RefNum); return Status; } } Status = SpSetKcmAttrInt (*RefNum, KCM_CLASS, Class); Status = SpXformFromPTRefNumImp (*RefNum, Xform); *RefNum = 0; return Status; }
/* 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; }
/* PTGetPTF writes a PT to external memory in a variety of formats. */ PTErr_t PTGetPTF ( PTRefNum_t PTRefNum, PTType_t format, KpInt32_t mBlkSize, PTAddr_t PTAddr) { PTErr_t errnum, PTstatus; KpHandle_t PTHdr, PTAttr, PTData; KpFd_t fd; KpInt32_t attrSize, resultSize, nBytes; PTRefNum_t resizePTRefNum = 0, thePTRefNum; KpChar_p memData; errnum = getPTStatus (PTRefNum); if ((errnum == KCP_PT_ACTIVE) || (errnum == KCP_PT_INACTIVE) || (errnum == KCP_SERIAL_PT)) { #if defined KCP_DIAG_LOG {KpChar_t string[256]; sprintf (string, "\nPTGetPTF\n PTRefNum %x, format %x, mBlkSize %d, PTAddr %x\n", PTRefNum, format, mBlkSize, PTAddr); kcpDiagLog (string);} #endif PTstatus = errnum; /* verify the dimensions of the grid table are valid for the specified format. */ errnum = gridDimValid (format, PTRefNum, &resizePTRefNum); if (errnum != KCP_SUCCESS) { goto ErrOut1; } if (resizePTRefNum != 0) { thePTRefNum = resizePTRefNum; /* resized PT made */ } else { thePTRefNum = PTRefNum; /* use original PT */ } /* determine the size the resized PT */ errnum = PTGetSizeF (thePTRefNum, format, &resultSize); if (errnum != KCP_SUCCESS) { goto ErrOut1; } if (resultSize > mBlkSize) { /* PT may not be larger than the buffer size */ errnum = KCP_PT_BLOCK_TOO_SMALL; goto ErrOut1; } PTAttr = getPTAttr (thePTRefNum); PTHdr = getPTHdr (thePTRefNum); PTData = getPTData (thePTRefNum); /* initialize memory file manager to write the PT */ if (KpOpen (NULL, "m", &fd, NULL, (KpGenericPtr_t)PTAddr, mBlkSize) != KCMS_IO_SUCCESS) { errnum = KCP_SYSERR_1; goto ErrOut1; } attrSize = getAttrSize (PTAttr); /* get size of attributes */ errnum = TpWriteHdr (&fd, format, PTHdr, attrSize); /* write the header info */ if (errnum != KCP_SUCCESS) { Kp_close (&fd); goto ErrOut1; } #if !defined KCP_ICC_ONLY switch (format) { case PTTYPE_FUTF: errnum = writeAttributes (&fd, PTAttr); /* write the attributes */ if (errnum != KCP_SUCCESS) { break; } default: break; } #endif /* if PT active, write data to external format */ if (((PTstatus == KCP_PT_ACTIVE) || (PTstatus == KCP_SERIAL_PT)) && (errnum == KCP_SUCCESS)) { errnum = TpWriteData (&fd, format, PTHdr, PTData); } (void) Kp_close (&fd); /* if the result PT size is smaller than the memory block size fill the end of the memory block with zeros */ nBytes = mBlkSize - resultSize; if (nBytes > 0) { memData = (KpChar_p)PTAddr + resultSize; while (nBytes--) { *memData++ = 0; } } } ErrOut1: if (resizePTRefNum != 0) { PTCheckOut (resizePTRefNum); } return (errnum); }
/* PTGetSizeF calculates the size of a PT in any format. */ PTErr_t PTGetSizeF (PTRefNum_t PTRefNum, PTType_t format, KpInt32_p mBlkSize) { PTErr_t errnum, errnum1; KpInt32_t extSize, intSize; KpHandle_t PTHdr, PTData; PTRefNum_t matrixPTRefNum; KpUInt32_t lutConfig; #if !defined KCP_ICC_ONLY KpHandle_t PTAttr; #endif #if !defined KCMS_NO_CRC KpChar_t strCRCmade[KCM_MAX_ATTRIB_VALUE_LENGTH+1]; KpInt32_t crc32; #endif errnum = getPTStatus (PTRefNum); if ((errnum == KCP_PT_ACTIVE) || (errnum == KCP_PT_INACTIVE) || (errnum == KCP_SERIAL_PT)) { if (mBlkSize == NULL) return (KCP_BAD_PTR); switch (format) { #if !defined KCP_ICC_ONLY case PTTYPE_FUTF: extSize = KCP_PT_HEADER_SIZE; /* size of external header */ break; #endif case PTTYPE_MFT1: case PTTYPE_MFT2: case PTTYPE_MFT2_VER_0: extSize = (2 * sizeof (KpInt32_t)) + (4 * sizeof (KpUInt8_t)) + (MF_MATRIX_DIM * MF_MATRIX_DIM * sizeof (KpInt32_t)); break; case PTTYPE_MAB1: case PTTYPE_MAB2: case PTTYPE_MBA1: case PTTYPE_MBA2: extSize = (7 * sizeof (KpInt32_t)) + (2 * sizeof (KpUInt8_t)) + sizeof (KpUInt16_t); errnum1 = getMatrixPTRefNum (PTRefNum, &matrixPTRefNum, &lutConfig); if (KCP_SUCCESS == errnum1) { extSize += ((MF_MATRIX_DIM * MF_MATRIX_DIM + MF_MATRIX_DIM) * sizeof (KpInt32_t)); } break; default: return (KCP_INVAL_PTTYPE); } if ((errnum == KCP_PT_ACTIVE) || (errnum == KCP_SERIAL_PT)) { /* when active, add size of external PT data block */ PTHdr = getPTHdr (PTRefNum); PTData = getPTData (PTRefNum); intSize = TpGetDataSize (PTHdr, PTData, format); if (intSize == 0) { PTRefNum_t resizePTRefNum; /* TpGetDataSize will return 0 if the grid table dimensions are not valid for the format specified. PTGetPTF will attempt to resize the grid table of the PT. Check if that resizing is possible */ errnum = gridDimValid (format, PTRefNum, &resizePTRefNum); if (errnum != KCP_SUCCESS) { return errnum; } /* Determine the size of the resized PT */ PTHdr = getPTHdr (resizePTRefNum); PTData = getPTData (resizePTRefNum); intSize = TpGetDataSize (PTHdr, PTData, format); PTCheckOut (resizePTRefNum); if (intSize == 0) { return KCP_INCON_PT; } } extSize += intSize; /* add size of data */ #if !defined KCMS_NO_CRC switch (format) { case PTTYPE_FUTF: errnum = TpCalCrc (PTHdr, PTData, &crc32); if (errnum == KCP_SUCCESS) { KpItoa(crc32, strCRCmade); PTSetAttribute(PTRefNum, KCM_CRC, strCRCmade); } break; default: break; } #endif } /* add size of attributes. Must be done after CRC calculation */ #if !defined KCP_ICC_ONLY switch (format) { case PTTYPE_FUTF: PTAttr = getPTAttr (PTRefNum); extSize += getAttrSize(PTAttr); /* plus size of attributes */ break; default: break; } #endif *mBlkSize = extSize; /* return external size of PT */ errnum = KCP_SUCCESS; } return (errnum); }
/* frees source fut on error */ PTErr_t fut2PT (fut_p *futSrc, KpInt32_t inSpace, KpInt32_t outSpace, KpInt32_t srcFormat, PTRefNum_p PTRefNumNew) { PTErr_t PTErr; fut_hdr_p PTHdr = NULL; KpHandle_t PTHdrH = NULL, PTDataH = NULL; KpChar_t colorSpaceAttr[20]; *PTRefNumNew = 0; if ( ! IS_FUT(*futSrc)) goto ErrOut1; PTHdr = allocBufferPtr (sizeof(fut_hdr_t)); /* get buffer for resultant info header */ if (PTHdr == NULL) { goto ErrOut4; } if (!fut_io_encode (*futSrc, PTHdr)) { /* make the info header */ goto ErrOut3; } PTHdr->srcFormat = srcFormat; PTDataH = fut_unlock_fut (*futSrc); if (PTDataH == NULL) { goto ErrOut2; } *futSrc = NULL; PTHdrH = unlockBufferPtr (PTHdr); /* unlock the header buffer */ if (PTHdrH == NULL) { goto ErrOut2; } PTHdr = NULL; PTErr = registerPT (PTHdrH, NULL, PTRefNumNew); /* enter PT into list */ if (PTErr != KCP_SUCCESS) { goto ErrOut0; } makeActive (*PTRefNumNew, PTDataH); /* activate the new PT */ if (inSpace != -1) { /* set the input color space attribute */ KpItoa (inSpace, colorSpaceAttr); PTErr = PTSetAttribute (*PTRefNumNew, KCM_IN_SPACE, colorSpaceAttr); } if (outSpace != -1) { /* set the output color space attribute */ KpItoa (outSpace, colorSpaceAttr); PTErr = PTSetAttribute (*PTRefNumNew, KCM_OUT_SPACE, colorSpaceAttr); } if (PTErr != KCP_SUCCESS) { goto ErrOut0; } getOut: return PTErr; ErrOut4: PTErr = KCP_NO_CHECKIN_MEM; goto ErrOut0; ErrOut3: PTErr = KCP_ENCODE_PTHDR_ERR; goto ErrOut0; ErrOut2: PTErr = KCP_MEM_UNLOCK_ERR; goto ErrOut0; ErrOut1: PTErr = KCP_BAD_ARG; ErrOut0: if (PTDataH != NULL) { *futSrc = fut_lock_fut (PTDataH); } if (*futSrc != FUT_NULL) fut_free (*futSrc); if (PTHdr != NULL) freeBufferPtr (PTHdr); if (PTHdrH != NULL) freeBuffer (PTHdrH); if (*PTRefNumNew != 0) PTCheckOut (*PTRefNumNew); goto getOut; }