Ejemplo n.º 1
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Create an SpXform_t from a data block containing a PT using the
 *	default grid size.  There is no RCS->LAB color space conversion.
 *	Used for importing the raw PT.
 *
 * AUTHOR
 * 	mjb
 *
 * DATE CREATED
 *	September 27, 1995
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpXformCreateFromDataNC (
				KpInt32_t	Size,
				KpLargeBuffer_t	Data,
				SpXform_t	FAR *Xform)
{

	SpStatus_t	Status;
	PTRefNum_t	RefNum;

	*Xform = NULL;

	Status = SpXformLoadImp (Data, Size, NO_DT_ICC_TYPE, SpSigNone, 
				SpSigNone, &RefNum);
	if (SpStatSuccess != Status)
		return Status;

	Status = SpXformFromPTRefNumNC (&RefNum, Xform);

	#if defined KCP_DIAG_LOG
	{KpChar_t	string[256];
	sprintf (string, "\nSpXformCreateFromDataEx\n *Xform %x\n",*Xform);
	kcpDiagLog (string); }
	#endif

	return Status;
}
Ejemplo n.º 2
0
fut_p
	get_linlab_fut (KpInt32_t		size,
					double			neutralInput,
					PTDataClass_t	iClass,
					PTDataClass_t	oClass)
{
fut_p		futp;
KpInt32_t	iomask, sizeArray[KCP_THIS_FUT_CHANS];
fut_ifunc_t	ifunArray[KCP_THIS_FUT_CHANS] = {NULL, yzfun, yzfun};
fut_ofunc_t	ofunArray[KCP_THIS_FUT_CHANS] = {ofun, ofun, ofun};
fData_t		fData;

	if (iClass) {}	if (oClass) {}

	#if defined KCP_DIAG_LOG
	{KpChar_t	string[256];
	sprintf (string, "get_linlab_fut\n size %d, neutralInput %f\n", size, neutralInput);
	kcpDiagLog (string); }
	#endif

	iomask = FUT_IN(FUT_XYZ) | FUT_OUT(FUT_XYZ);

	/* define neutral input position and grid point */
	fData.neutralInput = neutralInput;
	fData.neutralgrid = (double)(size / 2) / (double)(size - 1);

	/* assume all dimensions are the same */
	sizeArray[0] = size;
	sizeArray[1] = size;
	sizeArray[2] = size;

	futp = constructfut (iomask, sizeArray, &fData.std, ifunArray, NULL, ofunArray,
						iClass, oClass);

	#if defined KCP_DIAG_LOG
	saveFut (futp, "CP24.fut");
	#endif
				
	return (futp);
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
/*--------------------------------------------------------------------
 * 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;
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
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);
}
Ejemplo n.º 7
0
/***************************************************************************
 * FUNCTION NAME
 *      SpXformBufferDT
 *
 * DESCRIPTION
 *      This function copies the PT associated with the PTRefNum in
 *      the Xform to the Address given.  It will be in the format
 *      requested by the caller.  The SpXform is NOT freed by this
 *      function.
 *
 *
 
***************************************************************************/
SpStatus_t KSPAPI SpXformToBufferDT(SpXform_t	spXform,
				KpUInt32_t	LutType,
				KpInt32_t	SpDataType,
				KpUInt32_t	Datasize,
				SpHugeBuffer_t pXformData)
{

PTRefNum_t	refNum;
SpStatus_t	spStatus;
KpUInt32_t	PTDatasize;
PTErr_t		PTStat;
KpUInt32_t	MFType;
KpInt32_t	KcmDataType;

	spStatus = SpDTtoKcmDT (SpDataType, &KcmDataType);
	if (spStatus != SpStatSuccess) {
		return (spStatus);
	}

	/*      Get the Color Processor PTRefNum of the SpXform */
	spStatus = SpXformGetRefNum (spXform, &refNum);
	if (SpStatSuccess != spStatus)
		return spStatus;

/* determine type of transform to get */
	switch (LutType) {
	case SP_ICC_FUT:
		MFType = PTTYPE_FUTF;
		break;

	case SP_ICC_MFT1:
		MFType = PTTYPE_MFT1;
		break;

	case SP_ICC_MFT2:
		if (KcmDataType == KCM_ICC_TYPE_0)
			MFType = PTTYPE_MFT2_VER_0;
		else
			MFType = PTTYPE_MFT2;
		break;

	case SP_ICC_MAB1:
		MFType = PTTYPE_MAB1;
		break;

	case SP_ICC_MAB2:
		MFType = PTTYPE_MAB2;
		break;

	case SP_ICC_MBA1:
		MFType = PTTYPE_MBA1;
		break;

	case SP_ICC_MBA2:
		MFType = PTTYPE_MBA2;
		break;

	default:
		return SpStatOutOfRange;
	}

/* ask color processor for the size of the Transform */
	PTStat = PTGetSizeF (refNum, MFType, (KpInt32_t FAR *)&PTDatasize);
	if (KCP_SUCCESS != PTStat)
		return SpStatusFromPTErr(PTStat);

	if (PTDatasize > Datasize)
		return SpStatBufferTooSmall;

	#if defined KCP_DIAG_LOG
	{KpChar_t	string[256];
	sprintf (string, "\nSpXformToBufferDT\n spXform %x, PTRefNum %x", 
		spXform, pXformData);
	kcpDiagLog (string); }
	#endif

/* ask color processor for the Transform data */
	PTStat = PTGetPTF(refNum, MFType, 
			Datasize, (PTAddr_t) pXformData);

	return SpStatusFromPTErr(PTStat);

}
Ejemplo n.º 8
0
SpStatus_t KSPAPI SpXformToLutDT(SpXform_t	Xform,
				KpInt32_t	SpDataType,
				SpLut_t		*Lut,
				SpTransRender_t	*WhichRender,
				SpTransType_t	*WhichTransform,
				SpSig_t		*SpaceIn,
				SpSig_t		*SpaceOut,
				KpF15d16XYZ_t	*HdrWhite,
				KpF15d16XYZ_t	*MedWhite,
				KpUInt32_t	*ChainIn,
				KpUInt32_t	*ChainOut)
{
SpHugeBuffer_t	Buf;
char			*LutBuf;
KpUInt32_t		BufSize;
SpStatus_t		Status;
SpXformData_t   FAR *XformData;
KpInt32_t		KcmDataType;

	Status = SpDTtoKcmDT (SpDataType, &KcmDataType);
	if (Status != SpStatSuccess) {
		return (Status);
	}

	/* Set Up Private Structure to Populate */
	XformData = lockBuffer ((KcmHandle)Xform);
	if (NULL == XformData)
		return SpStatBadXform;

	/* Set Up Lut Size based on Lut Type and size */
	switch ( XformData->LutType )
	{	
	case SpTypeLut8:
		XformData->LutSize =  SP_ICC_MFT1;
		break;
	case SpTypeLut16:
		XformData->LutSize = SP_ICC_MFT2;
		break;
	case SpTypeLutAB:
		if ((XformData->LutSize == 0) ||
		    (XformData->LutSize == 16))
			XformData->LutSize = SP_ICC_MAB2;
		else
			XformData->LutSize = SP_ICC_MAB1;
		break;
	case SpTypeLutBA:
		if ((XformData->LutSize == 0) ||
		    (XformData->LutSize == 16))
			XformData->LutSize = SP_ICC_MBA2;
		else
			XformData->LutSize = SP_ICC_MBA1;
		break;
	} /* end switch */

	#if defined KCP_DIAG_LOG
	{KpChar_t	string[256];
	sprintf (string, "\nSpXformToLutDT\n Xform %x, PTRefNum %x, Lut %x", 
		Xform, XformData->PTRefNum, Lut);
	kcpDiagLog (string); }
	#endif

	Status = SpXformGetDataFromCP  (XformData->PTRefNum,
					XformData->LutSize,
					KcmDataType,
					&BufSize,
					&Buf);

	if (Status != SpStatSuccess)
	{
		unlockBuffer ((KcmHandle)Xform);
		return Status;
	}

	Lut->LutType = XformData->LutType;

	/* Move past the tag and Reserved */
	LutBuf = (char *)Buf;
	LutBuf += 8;
	Status = SpLutToPublic(LutBuf, Lut);

	/* Clear White Points */
	HdrWhite->X = MedWhite->X =
	HdrWhite->Y = MedWhite->Y =
	HdrWhite->Z = MedWhite->Z = 0;

	if (Status == SpStatSuccess)
	{
		*WhichRender     = XformData->WhichRender;
		*WhichTransform  = XformData->WhichTransform;
		*SpaceIn         = XformData->SpaceIn;
		*SpaceOut        = XformData->SpaceOut;
		if (XformData->HdrWPValid) {
			HdrWhite->X       = XformData->HdrWtPoint.X;
			HdrWhite->Y       = XformData->HdrWtPoint.Y;
			HdrWhite->Z       = XformData->HdrWtPoint.Z;
		}
		if (XformData->MedWPValid) {
			MedWhite->X      = XformData->MedWtPoint.X;
			MedWhite->Y      = XformData->MedWtPoint.Y;
			MedWhite->Z      = XformData->MedWtPoint.Z;
		}
		*ChainIn         = XformData->ChainIn;
		*ChainOut        = XformData->ChainOut;
	}
	SpFree(Buf);
	unlockBuffer ((KcmHandle)Xform);
	return Status;
}
Ejemplo n.º 9
0
/* 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);
}
Ejemplo n.º 10
0
/* PTActivate reads the PT data from an external memory block and
 * sets up the technology specific PT memory structures.  Before loading
 * the PT, check to make sure that it matches the "checked in" info.
 */
PTErr_t
	PTActivate(	PTRefNum_t	PTRefNum,
				KpInt32_t	mBlkSize,
				PTAddr_t	PTAddr)
{
PTErr_t		errnum;
KpFd_t		fd;
KpHandle_t	PTHdr, PTData, PTHdr2;
fut_hdr_p	futp;
#if !defined KCMS_NO_CRC
KpChar_t 	strCRCmade[KCM_MAX_ATTRIB_VALUE_LENGTH+1];
KpChar_t 	strCRCfound[KCM_MAX_ATTRIB_VALUE_LENGTH+1];
KpInt32_t	crcAttrSize, crc32;
#endif
KpInt32_t	attrSize;
PTType_t	format;

	errnum = getPTStatus (PTRefNum);
	if (errnum != KCP_PT_INACTIVE) {
		goto ErrOut1;
	}

	/* initialize memory file manager */
	if (KpOpen (NULL, "m", &fd, NULL, (KpGenericPtr_t)PTAddr, mBlkSize) != KCMS_IO_SUCCESS) {
		errnum = KCP_SYSERR_1;
		goto ErrOut1;
	}

/* read in the encoded header, verify that its the same as the original, then discard */
	errnum = TpReadHdr (&fd, &PTHdr2, &format);
	if (errnum != KCP_SUCCESS ) {
		goto ErrOut2;
	}

	#if defined KCP_DIAG_LOG
	{KpChar_t	string[256];
	sprintf (string, "\nPTActivate\n PTRefNum %x, mBlkSize %d, PTAddr %x, format %x\n",
						PTRefNum, mBlkSize, PTAddr, format);
	kcpDiagLog (string);}
	#endif

/* get and save size of attributes */
    futp = lockBuffer (PTHdr2);
	attrSize = futp->idstr_len;
	unlockBuffer (PTHdr2);

	PTHdr = getPTHdr (PTRefNum);	/* get the original PT header */

/* make sure the PT header and checkin info match */
	errnum = TpCompareHdr (PTHdr, PTHdr2);

	(void) TpFreeHdr (PTHdr2);		/* free the header */

	if (errnum != KCP_SUCCESS) {	/* then check for an error in hdrVerify */
		goto ErrOut2;
	}

#if !defined KCP_ICC_ONLY
	switch (format) {
	case PTTYPE_FUTF:						/* discard the attribute info */
		if (Kp_skip (&fd, attrSize) != KCMS_IO_SUCCESS){ /* may have been setAttribute after checkin */
			errnum = KCP_PTERR_3;
			goto ErrOut2;
		}

		break;

	default:
		break;
	}
#endif

	errnum = TpReadData (&fd, format, PTRefNum, PTHdr, &PTData);		/* get the PT data */
	if (errnum == KCP_SUCCESS) {
		if (PTMemTest () == 0) {			/* enough memory to continue operations? */
			errnum = KCP_NO_ACTIVATE_MEM;
			goto ErrOut3;
		}

	#if !defined KCMS_NO_CRC
		errnum = TpCalCrc (PTHdr, PTData, &crc32);	/* calculate the CRC */
		if (errnum == KCP_SUCCESS) {
			KpItoa(crc32, strCRCmade);
			crcAttrSize = KCM_MAX_ATTRIB_VALUE_LENGTH;
			errnum = PTGetAttribute(PTRefNum, KCM_CRC, &crcAttrSize, strCRCfound);

			if (errnum == KCP_INVAL_PTA_TAG) {		/* if not present, just set it */
				PTSetAttribute(PTRefNum, KCM_CRC, strCRCmade);
				errnum = KCP_SUCCESS;
			}
			else {
/*				if ((errnum == KCP_SUCCESS)*/			/* if present, must match */ 
/*					&& (strcmp (strCRCmade, strCRCfound) != 0)) { */
/*					errnum = KCP_INCON_PT; */
/*					goto ErrOut3; */
/*				} */
			}
		}
	#endif
	}

	if (errnum == KCP_SUCCESS) {	/* Everything's OK, now activate */
		makeActive (PTRefNum, PTData);
	}

ErrOut2:
	(void) Kp_close (&fd);
ErrOut1:
	return (errnum);


ErrOut3:
	(void) TpFreeData (PTData);	/* Release the PT memory */
	goto ErrOut2;
}