コード例 #1
0
/***************************************************************************
 * FUNCTION NAME
 *      SpStringToTextDesc
 *
 * DESCRIPTION
 *      This function converts stings to tags of type Sp_AT_TextDesc
 * to a string.  It allocates memory for the iso, unicode and mac 
 * strings which must be freed.  SpFreeTextDesc can be called to free 
 * that memory.
***************************************************************************/
SpStatus_t SpStringToTextDesc(KpChar_p pString,
				SpTextDesc_t *pTextDesc)
{
KpInt32_t	length, index, macScriptLen = 67;
KpChar_p	pSrcStr, pDestStr;
KpUInt16_t	data16;
KpUInt16_p	pDestStr16;

	/* Allocate memory for the stings */
	length = strlen (pString);
	pTextDesc->IsoStr = (char *) allocBufferPtr (length+1);
	pTextDesc->UniStr = (unsigned short *) allocBufferPtr((length+2)*2);
	if ((NULL == pTextDesc->IsoStr) ||
	    (NULL == pTextDesc->UniStr)) {
		SpFreeTextDesc (pTextDesc);
		return SpStatMemory;
	}
 
	/* copy the string to the isoString */
	pSrcStr = pString;
	pDestStr = pTextDesc->IsoStr;
	strcpy (pDestStr, pSrcStr);

	/* convert the string to unicode */
	pSrcStr = pString;
	pDestStr16 = pTextDesc->UniStr;
	pTextDesc->UniLangCode = 0;
	for (index = 0; index < length; index++) {
		data16 = *pSrcStr++;
		*pDestStr16++ = data16;
	}
	data16 = 0;
	*pDestStr16++ = data16;
 
	/* convert the string to macintosh script */
	pSrcStr = pString;
	pDestStr = pTextDesc->MacStr;
	pTextDesc->MacScriptCode = 0;
	if (length >= macScriptLen) {
		length = macScriptLen - 1;
	}
	pTextDesc->MacCount = (char) (length+1);
	strncpy (pDestStr, pSrcStr, length+1);
	pDestStr += length;
	*pDestStr = 0;
 
	return SpStatSuccess;
} /* SpStringToTextDesc */
コード例 #2
0
/***************************************************************************
 * FUNCTION NAME
 *      SpStringToMultiLang
 *
 * DESCRIPTION
 *      This function converts stings to English Unicode in a MultiLang Tag
***************************************************************************/
SpStatus_t SpStringToMultiLang(KpChar_p pString, KpInt16_t Language, KpInt16_t Country,
                                SpMultiLang_t *pMultiLang)
{
KpInt32_t       length, index;
KpChar_p        pSrcStr;
KpUInt16_t      data16;
KpUInt16_p      pDestStr16;

        pMultiLang->StringInfo = (SpUnicodeInfo_t *)allocBufferPtr(sizeof(SpUnicodeInfo_t));
        if (NULL == pMultiLang->StringInfo)
                return SpStatMemory;

        length = strlen (pString);

        /* Set up for place holder for Profile Seq Desc Tag */
        pMultiLang->Count = 0;

        pMultiLang->RecSize = 12;
        pMultiLang->StringInfo[0].LanguageCode = Language;
        pMultiLang->StringInfo[0].CountryCode = Country;
        pMultiLang->StringInfo[0].StringLength = 2 * length;
        if (length > 0)
        {
                pMultiLang->Count = 1;

                /* Allocate memory for the stings */
                pMultiLang->StringInfo[0].UniString =
                        (unsigned short *) allocBufferPtr(2 * length);
                if (NULL == pMultiLang->StringInfo[0].UniString) {
                        freeBufferPtr(pMultiLang->StringInfo);
                        return SpStatMemory;
                }
                /* convert the string to unicode */
                pSrcStr = pString;
                pDestStr16 = pMultiLang->StringInfo[0].UniString;
                for (index = 0; index < length; index++) {
                        data16 = *pSrcStr++;
                        *pDestStr16++ = data16;
                }
        }

        return SpStatSuccess;
} /* SpStringToMultiLang */
コード例 #3
0
/***************************************************************************
 * FUNCTION NAME
 *      SpProfileSetLinkSeqDesc
 *
 * DESCRIPTION
 *      This function creates the Profile Sequence Description tag for
 * the device link profile pointed to by pProfile.  The information
 * needed to form the sequence description is contained in the
 * SpDevLinkPB structure pointed to by pDevLinkDesc.  A sequence record 
 * is created for each profile in the profile list.  The sequence records
 * are used to make the sequence description.
 *
***************************************************************************/
SpStatus_t SpProfileSetLinkSeqDesc(SpProfile_t		pProfile,
				   SpDevLinkPB_p	pDevLinkDesc)
{
KpInt32_t			index, numProfiles,numRecords;
SpProfListEntry_p		pCurProfEntry;
SpProfileSeqDescRecord_t	*pSeqRecords, *pCurrentRecord;
SpTagValue_t			tagValue;
SpStatus_t			spStatus;

	/* Allocate the memory for the profile sequence records */
	numProfiles = pDevLinkDesc->numProfiles;
	pSeqRecords = (SpProfileSeqDescRecord_t *)
			allocBufferPtr(sizeof(SpProfileSeqDescRecord_t) *
			numProfiles);
	if (NULL == pSeqRecords) {
		return SpStatMemory;
	}
 
	/* For each profile in the profile list make a 
	   profile sequence record */
	pCurrentRecord = pSeqRecords;
	pCurProfEntry = pDevLinkDesc->pProfileList;
	numRecords = 0;
	for (index = 0; index < pDevLinkDesc->numProfiles; index++) {
		spStatus = SpProfileCreateSeqRecord(pCurProfEntry->profile,
				pCurrentRecord);
		if (SpStatSuccess != spStatus) {
			goto getOut;
		}
		numRecords++;
		pCurrentRecord++;
		pCurProfEntry++;
	}

	/* Create the profile sequence description tag and 
	   add it to the profile */
	tagValue.TagId = SpTagProfileSeqDesc;
	tagValue.TagType = Sp_AT_ProfileSeqDesc;
	tagValue.Data.ProfileSeqDesc.Count = numRecords;
	tagValue.Data.ProfileSeqDesc.Records = pSeqRecords;
	spStatus = SpTagSet (pProfile, &tagValue);
 
	/* Free all of the sequence records */
getOut:
	pCurrentRecord = pSeqRecords;
	for (index = 0; index < numRecords; index++) {
		SpProfileFreeSeqRecord (pCurrentRecord);
		pCurrentRecord++;
	}
	freeBufferPtr (pSeqRecords);
	return spStatus;
} /* SpProfileSetLinkSeqDesc */
コード例 #4
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Map an entire file.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	November 9, 1993
 *------------------------------------------------------------------*/
void FAR *KpMapFileEx (
				KpChar_p		FileName,
				KpFileProps_t	FAR *FileProps,
				KpChar_p		Mode,
				KpMapFile_t	FAR *MapFileCtl)
{
/* validate mode */
	switch (*Mode) {
	case 'R':
	case 'r':
#if 0
	case 'w':
#endif
		break;
	
	default:
		return NULL;
	}

/* get the size of the file */
	if (!KpFileSize (FileName, FileProps, &MapFileCtl->NumBytes))
		return NULL;

/* allocate buffer to hold file */
	MapFileCtl->Ptr = allocBufferPtr (MapFileCtl->NumBytes);
	if (NULL == MapFileCtl->Ptr)
		return NULL;

/* open the file */
	if (!KpFileOpen (FileName, Mode, FileProps, &MapFileCtl->Fd)) {
		freeBufferPtr (MapFileCtl->Ptr);
		return NULL;
	}

/* read file into the buffer */
	if (!KpFileRead (MapFileCtl->Fd, MapFileCtl->Ptr, &MapFileCtl->NumBytes)) {
		freeBufferPtr (MapFileCtl->Ptr);
		KpFileClose (MapFileCtl->Fd);
		return NULL;
	}

/* done with file, close it */
	if ('r' == *Mode) {
		KpFileClose (MapFileCtl->Fd);
		MapFileCtl->Fd = -1;
	}
	MapFileCtl->Mode = *Mode;

	return MapFileCtl->Ptr;
}
コード例 #5
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Return the header for the profile.
 *
 * AUTHOR
 * 	doro
 *
 * DATE CREATED
 *	October 23, 1995
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileLoadHeader(
    char                    *Filename,
    SpFileProps_t		*Props,
    SpHeader_t              FAR *Header)
{
    SpHugeBuffer_t BufferAddress;
    SpStatus_t     Status = SpStatBadProfile;
    KpFileId       FD;
    char          *name;
    KpUInt32_t     Read_OK;
    KpInt32_t     Read_Amount = HEADER_SIZE;
    KpFileProps_t  fileProps;

    if (!SpIsICCProfile(Filename, Props))
        return (SpStatBadProfile);

    name = Filename;

    BufferAddress = allocBufferPtr(HEADER_SIZE);
    if (BufferAddress == NULL)
        return (SpStatMemory);

#if defined (KPMAC)
    SpCvrtSpFileProps(Props, &fileProps);
#endif
    if (KpFileOpen(name, "r", &fileProps, &FD)) /* 0 = not opened */
    {
        /* Read HEADER_SIZE into Buffer */
        Read_OK =  KpFileRead(FD, BufferAddress, &Read_Amount);

        /* Close File */
        if (!KpFileClose(FD))
            Status = SpStatBadProfile;

        if (Read_OK)
        {
            Status = SpHeaderToPublic(BufferAddress, HEADER_SIZE, Header);
        }
    }
    freeBufferPtr(BufferAddress);
    return Status;

}
コード例 #6
0
/***************************************************************************
 * FUNCTION NAME
 *      SpProfileSetLinkDesc
*
 * DESCRIPTION
 *      This function creates the Profile Description tag for the
 * device link profile pointed to by pProfile.  The information needed 
 * to form the description string is contained in the SpDevLinkPB 
 * structure pointed to by pDevLinkDesc.  The description string 
 * is formed by taking the manufacture, model and device color space 
 * from the first profile in the profile list and taking the 
 * manufacturer, model and connection color space from the last profile 
 * in the list.
 *
***************************************************************************/
SpStatus_t SpProfileSetLinkDesc(SpProfile_t	pProfile,
				SpDevLinkPB_p	pDevLinkDesc)
{
KpTChar_t	manufacturer1[SpMaxTextDesc], model1[SpMaxTextDesc];
KpTChar_t	manufacturer2[SpMaxTextDesc], model2[SpMaxTextDesc];
KpTChar_p	pDescStr;
KpInt32_t	length;
SpProfListEntry_p	pCurProfEntry;
SpTagValue_t	tagValue;
SpStatus_t	spStatus;

	/* Get the manufacturer information from the first profile */
	pCurProfEntry = pDevLinkDesc->pProfileList;
	strcpy (manufacturer1, "Unknown");
	spStatus = SpTagGetById(pCurProfEntry->profile,
				SpTagDeviceMfgDesc,
				&tagValue);

	if (SpStatSuccess == spStatus) {
		length = sizeof (manufacturer1);
		SpTagGetString(&tagValue, &length,  manufacturer1);
		SpTagFree(&tagValue);
	}

	/*	Get the model information from the first profile */
	strcpy(model1, "Unknown");
	spStatus = SpTagGetById(pCurProfEntry->profile,
				SpTagDeviceModelDesc,
				&tagValue);
	if (SpStatSuccess == spStatus) {
		length = sizeof (model1);
		SpTagGetString(&tagValue, &length, model1);
		SpTagFree(&tagValue);
	}
 
	/* Get the manufacturer information from the last profile */
	pCurProfEntry = pDevLinkDesc->pProfileList +
				(pDevLinkDesc->numProfiles - 1);
	strcpy(manufacturer2, "Unknown");
	spStatus = SpTagGetById(pCurProfEntry->profile,
				SpTagDeviceMfgDesc,
				&tagValue);
	if (SpStatSuccess == spStatus) {
		length = sizeof (manufacturer2);
		SpTagGetString(&tagValue, &length, manufacturer2);
		SpTagFree(&tagValue);
	}
 
	/* Get the model information from the last profile */
	strcpy(model2, "Unknown");
	spStatus = SpTagGetById(pCurProfEntry->profile,
				SpTagDeviceModelDesc,
				&tagValue);
	if (SpStatSuccess == spStatus) {
		length = sizeof (model2);
		SpTagGetString(&tagValue, &length, model2);
		SpTagFree(&tagValue);
	}
 
 
	/* Allocate memory for the description string */
	length = strlen(manufacturer1) +
			strlen(model1) + 
			strlen(manufacturer2) +
			strlen(model2) + 7;

	pDescStr = (KpTChar_p)allocBufferPtr(length+1);
	if (NULL == pDescStr) {
		return SpStatMemory;
	}
 
	/* Form the description string */
	/* sprintf(pDescStr, "%s %s %s to %s %s %s",
		manufacturer1, model1, colorSpace1,
		manufacturer2, model2, colorSpace2); */
	strcpy(pDescStr, manufacturer1);
	strcat(pDescStr, " ");
	strcat(pDescStr, model1);
	strcat(pDescStr, " to ");
	strcat(pDescStr, manufacturer2);
	strcat(pDescStr, " ");
	strcat(pDescStr, model2);

	/* Convert the string to a text description tag and
	   add it to the profile */
	spStatus = SpStringToTextDesc(pDescStr,
				&tagValue.Data.TextDesc);
	freeBufferPtr(pDescStr);
	if (SpStatSuccess != spStatus) {
		return spStatus;
	}

	tagValue.TagId = SpTagProfileDesc;
	tagValue.TagType = Sp_AT_TextDesc;
	spStatus = SpTagSet (pProfile, &tagValue);
	SpFreeTextDesc (&tagValue.Data.TextDesc);

	return spStatus;
 
} /* SpProfileSetLinkDesc */
コード例 #7
0
/***************************************************************************
 * FUNCTION NAME
 *      SpProfileCreateMLSeqRecord
 *
 * DESCRIPTION
 *      This function creates the Profile Sequence record for the
 * profile pointed to by pProfile.  The Profile Sequence record to 
 * build is pointed to by pSeqRecord.
 *
***************************************************************************/
SpStatus_t SpProfileCreateMLSeqRecord(SpProfile_t		pProfile,
			SpProfileSeqDescRecord2_t	*pSeqRecord)
{
SpHeader_t	header;
SpTagValue_t	tagValue;
SpStatus_t	spStatus;
KpChar_p	CString;
KpInt32_t	BufSize;

	/* Get the profiles header */
	spStatus = SpProfileGetHeader (pProfile, &header);
	if (SpStatSuccess != spStatus) {
		return spStatus;
	}
 
	/* Copy the manufacturer, model, attributes and technology
	   fields into the sequence record */
	pSeqRecord->DeviceManufacturer = header.DeviceManufacturer;
	pSeqRecord->DeviceModel = header.DeviceModel;
	pSeqRecord->DeviceAttributes.hi = header.DeviceAttributes.hi;
	pSeqRecord->DeviceAttributes.lo = header.DeviceAttributes.lo;

	/* Get the technology tag*/
	spStatus = SpTagGetById(pProfile, 
				SpTagTechnology,
				&tagValue);
	if (SpStatSuccess != spStatus) 
		pSeqRecord->Technology = SpSigNone;
	else 
	{
		pSeqRecord->Technology = tagValue.Data.Signature;
		SpTagFree(&tagValue);
	}

	/* Get the manufacturer description */
	spStatus = SpTagGetById(pProfile, 
				SpTagDeviceMfgDesc,
				&tagValue);
	if (SpStatSuccess != spStatus) {
		spStatus = SpStringToMultiLang("", SpEnglish, SpUSA, &tagValue.Data.MultiLang);
		if (SpStatSuccess != spStatus) {
			return spStatus;
		}
	} else if (tagValue.TagType == Sp_AT_TextDesc)
	{
		BufSize = strlen(tagValue.Data.TextDesc.IsoStr) + 1;
		CString = (char *) allocBufferPtr (BufSize);
		spStatus = SpTagGetString(&tagValue, &BufSize, CString);
		SpTagFree(&tagValue);
		spStatus = SpStringToMultiLang(CString, SpEnglish, SpUSA, &tagValue.Data.MultiLang);
		freeBufferPtr(CString);
		if (SpStatSuccess != spStatus) 
			return spStatus;
	}

	pSeqRecord->DeviceManufacturerDesc.TagType = SpTypeMultiLanguage;
	pSeqRecord->DeviceManufacturerDesc.Reserved = 0;
	pSeqRecord->DeviceManufacturerDesc.MLDesc = tagValue.Data.MultiLang;

	/* Get the model description */
	spStatus = SpTagGetById(pProfile, 
				SpTagDeviceModelDesc,
				&tagValue);
	if (SpStatSuccess != spStatus) {
		spStatus = SpStringToMultiLang("", SpEnglish, SpUSA, &tagValue.Data.MultiLang);
		if (SpStatSuccess != spStatus) {
			return spStatus;
		}
	} else if (tagValue.TagType == Sp_AT_TextDesc)
	{
		BufSize = strlen(tagValue.Data.TextDesc.IsoStr) + 1;
		CString = (char *) allocBufferPtr (BufSize+1);
		spStatus = SpTagGetString(&tagValue, &BufSize, CString);
		SpTagFree(&tagValue);
		spStatus = SpStringToMultiLang(CString, SpEnglish, SpUSA, &tagValue.Data.MultiLang);
		freeBufferPtr(CString);
		if (SpStatSuccess != spStatus) 
			return spStatus;
	}

	pSeqRecord->DeviceModelDesc.TagType = SpTypeMultiLanguage;
	pSeqRecord->DeviceModelDesc.Reserved = 0;
	pSeqRecord->DeviceModelDesc.MLDesc = tagValue.Data.MultiLang;

	return SpStatSuccess;
} /* SpProfileCreateMLSeqRecord */
コード例 #8
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Test profile with header and or tag search criteria and report status
 *
 * AUTHOR
 * 	Sakey
 *
 * DATE CREATED
 *	July, 2002
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileCheckEx(
                                SpSearch_p              SearchValue,
                                char				*Filename,
								SpFileProps_t		*Props)
{
	SpStatus_t			status;
	SpHeader_t			Header;
	SpTagValue_t		tagValue;

	KpInt32_t			Passed[SPSEARCH_LIST];
	KpInt32_t			Tested[SPSEARCH_LIST];
	KpInt32_t			i, j, critSize;
	SpSearchCriterion_t *criterion;

#define	TAGID_LIST 5	
	SpTagId_t			TagIdsPassed[TAGID_LIST];
	SpTagId_t			TagIdsTested[TAGID_LIST];
	SpTagId_t			*pTagIdsPassed = TagIdsPassed;
	SpTagId_t			*pTagIdsTested = TagIdsTested;
	KpInt32_t			TagCount = 0;

	if (NULL == SearchValue)
		return SpStatIncompatibleArguments;

	critSize = SearchValue->critSize;
	criterion = SearchValue->criterion;

	status = SpProfileLoadHeader (Filename, Props, &Header);

	if (SpStatSuccess != status)
		return status;
	
	
	for (i = 0; i < SPSEARCH_LIST; i++)
	{
		 /* preset all entries in PassedEvalArray to Not Tested and failed . */
		Passed[i]  = 0;
		Tested[i]  = 0;
	}
	
	/* count up the number of tag checks requested. */
	for (i = 0; i < SearchValue->critCount; i++)
	{
		if ((SPSEARCH_ENUMTAGVALUE_EQUAL == criterion->SearchElement) ||
			(SPSEARCH_ENUMTAGVALUE_NOTEQUAL == criterion->SearchElement))
			TagCount++;

		 criterion = (SpSearchCriterion_t *)(critSize + (KpUInt8_p)criterion);
	}
	criterion = SearchValue->criterion;

	if (TAGID_LIST < TagCount)
	{
		/* allocate the tested/passed arrays */
		pTagIdsTested = allocBufferPtr( TagCount * sizeof(SpTagId_t));
		if (NULL == pTagIdsTested)
			return SpStatMemory;

		pTagIdsPassed = allocBufferPtr( TagCount * sizeof(SpTagId_t));
		if (NULL == pTagIdsPassed)
			return SpStatMemory;
	}

	/* preset all entries in Tag PassedEvalArrays to Not Tested and failed . */
	for (i = 0; i < TagCount; i++)
	{
		pTagIdsTested[i] = 0;
		pTagIdsPassed[i] = 0;
	}

   /* Loop thru the parameters, test the value based upon the Field
	*   Set that it Passed if it did.  Set that it was tested always
	*/
	for (i = 0; i < SearchValue->critCount; i++)
	{
		switch (criterion->SearchElement)
		{
		case SPSEARCH_PREFERREDCMM       :
			if (criterion->SearchValue.Signature ==
									(KpInt32_t) Header.CMMType)
			   Passed[SPSEARCH_PREFERREDCMM] = 1;
			Tested[SPSEARCH_PREFERREDCMM]    = 1;
			break;

		case SPSEARCH_VERSION            :
			if (criterion->SearchValue.Value     ==
									 Header.ProfileVersion)
			   Passed[SPSEARCH_VERSION]      = 1;
			Tested[SPSEARCH_VERSION]         = 1;
			break;

		case SPSEARCH_PROFILECLASS       :
			if (criterion->SearchValue.Signature ==
								 Header.DeviceClass)
			   Passed[SPSEARCH_PROFILECLASS] = 1;
			Tested[SPSEARCH_PROFILECLASS]    = 1;
			break;

		case SPSEARCH_DEVICECOLORSPACE   :
			if (criterion->SearchValue.Signature ==
							  Header.DataColorSpace)
			   Passed[SPSEARCH_DEVICECOLORSPACE] = 1;
			Tested[SPSEARCH_DEVICECOLORSPACE]    = 1;
			break;

		case SPSEARCH_CONNECTIONSPACE    :
			if (criterion->SearchValue.Signature ==
					   Header.InterchangeColorSpace)
			   Passed[SPSEARCH_CONNECTIONSPACE] = 1;
			Tested[SPSEARCH_CONNECTIONSPACE]    = 1;
			break;

		 /* Only use ONDATE value for all date testing since more
		  * than one value can be given for an attribute */
		case SPSEARCH_BEFOREDATE         :
			if (BEFORE == TestHeaderDate(
							&Header.DateTime,
							&criterion->SearchValue.Date))
			   Passed[SPSEARCH_ONDATE]          = 1;
			Tested[SPSEARCH_ONDATE]             = 1;
			break;

		case SPSEARCH_ONDATE             :
			if (SAME   == TestHeaderDate(
							&Header.DateTime,
							&criterion->SearchValue.Date))
			   Passed[SPSEARCH_ONDATE]          = 1;
			Tested[SPSEARCH_ONDATE]             = 1;
			break;

		case SPSEARCH_AFTERDATE          :
			if (AFTER  == TestHeaderDate(
							&Header.DateTime,
							&criterion->SearchValue.Date))
			   Passed[SPSEARCH_ONDATE]          = 1;
			Tested[SPSEARCH_ONDATE]             = 1;
			break;

		case SPSEARCH_PLATFORM           :
			if (criterion->SearchValue.Signature ==
									Header.Platform)
			   Passed[SPSEARCH_PLATFORM] = 1;
			Tested[SPSEARCH_PLATFORM]    = 1;
			break;

		case SPSEARCH_PROFILEFLAGS       :
			if (criterion->SearchValue.Value     ==
									   Header.Flags)
			   Passed[SPSEARCH_PROFILEFLAGS] = 1;
			Tested[SPSEARCH_PROFILEFLAGS]    = 1;
			break;

		case SPSEARCH_DEVICEMFG          :
			if (criterion->SearchValue.Signature ==
						  Header.DeviceManufacturer)
			   Passed[SPSEARCH_DEVICEMFG] = 1;
			Tested[SPSEARCH_DEVICEMFG]    = 1;
			break;

		case SPSEARCH_DEVICEMODEL        :
			if (criterion->SearchValue.Signature ==
								 Header.DeviceModel)
			   Passed[SPSEARCH_DEVICEMODEL] = 1;
			Tested[SPSEARCH_DEVICEMODEL]    = 1;
			break;

		case SPSEARCH_DEVICEATTRIBUTESHI :
			if (criterion->SearchValue.Value     ==
						 Header.DeviceAttributes.hi)
			   Passed[SPSEARCH_DEVICEATTRIBUTESHI] = 1;
			Tested[SPSEARCH_DEVICEATTRIBUTESHI]    = 1;
			break;

		case SPSEARCH_DEVICEATTRIBUTESLO :
			if (criterion->SearchValue.Value     ==
						 Header.DeviceAttributes.lo)
			   Passed[SPSEARCH_DEVICEATTRIBUTESLO] = 1;
			Tested[SPSEARCH_DEVICEATTRIBUTESLO]    = 1;
			break;

		case SPSEARCH_RENDERINGINTENT    :
			if (criterion->SearchValue.Signature ==
							 (KpInt32_t) Header.RenderingIntent)
			   Passed[SPSEARCH_RENDERINGINTENT] = 1;
			Tested[SPSEARCH_RENDERINGINTENT]    = 1;
			break;

		case SPSEARCH_ILLUMINANT         :
			if ((criterion->SearchValue.XYZ.X    ==
								Header.Illuminant.X) &&
				(criterion->SearchValue.XYZ.Y    ==
								Header.Illuminant.Y) &&
				(criterion->SearchValue.XYZ.Z    ==
								Header.Illuminant.Z))
			   Passed[SPSEARCH_ILLUMINANT] = 1;
			Tested[SPSEARCH_ILLUMINANT]    = 1;
			break;

		case SPSEARCH_ORIGINATOR         :
		   if (criterion->SearchValue.Signature ==
								Header.Originator)
			   Passed[SPSEARCH_ORIGINATOR] = 1;
		   Tested[SPSEARCH_ORIGINATOR]    = 1;
		   break;

		case SPSEARCH_PROFILEID         :
		   if ((criterion->SearchValue.ProfileID.a ==
								Header.ProfileID.a) &&
			   (criterion->SearchValue.ProfileID.b ==
								Header.ProfileID.b) &&
			   (criterion->SearchValue.ProfileID.c ==
								Header.ProfileID.c) &&
			   (criterion->SearchValue.ProfileID.d ==
								Header.ProfileID.d))
			   Passed[SPSEARCH_ORIGINATOR] = 1;
		   Tested[SPSEARCH_ORIGINATOR]    = 1;
		   break;

		case SPSEARCH_ENUMTAGVALUE_EQUAL	:
		case SPSEARCH_ENUMTAGVALUE_NOTEQUAL	:		
			/* find the matching tag ID or the first unused one */
			for(j = 0; j < TagCount; j++)
			{
				if ((pTagIdsTested[j] == criterion->SearchValue.Tag.TagId) || 
					(0 == pTagIdsTested[j]))
				{
					/* mark this tag as tested */
					pTagIdsTested[j] = criterion->SearchValue.Tag.TagId;
					break;
				}
			}
			/* load the tag */
			status = SpProfileLoadTag(Filename, Props, criterion->SearchValue.Tag.TagId, &tagValue);
			if (SPSEARCH_ENUMTAGVALUE_EQUAL == criterion->SearchElement) 
			{
				if ((SpStatSuccess == status) &&
					(criterion->SearchValue.Tag.TagEnum == tagValue.Data.TagEnum))
				{
					pTagIdsPassed[j] = pTagIdsTested[j];
				}
			}
			else
			{
				if ((SpStatSuccess != status) ||
					(criterion->SearchValue.Tag.TagEnum != tagValue.Data.TagEnum))
				{
					pTagIdsPassed[j] = pTagIdsTested[j];
				}
			}
			if (SpStatSuccess == status)
			{
				/* free allocated resources */
				SpTagFree(&tagValue);
			}
			break;
		case SPSEARCH_TIMEORDER:
		default:
		   /* No special processing */
		   break;
		}
 		criterion = (SpSearchCriterion_t *)(critSize + (KpUInt8_p)criterion);
	}
	/* assume success */ 
	status = SpStatSuccess;
   /* Loop thru enumeration types, Checking Passed vs Tested
	* for return value
	*/
	for (i = 0; i < SPSEARCH_LIST; i++)
	{
		if (Tested[i] && !Passed[i])
			status = SpStatBadProfile;
	}

	if (0 < TagCount)
	{
		for(j = 0; j < TagCount; j++)
		{
			if (pTagIdsTested[j] != pTagIdsPassed[j])
				status = SpStatBadProfile;
		}

		if (TAGID_LIST < TagCount)
		{
			freeBufferPtr( (KpGenericPtr_t)pTagIdsTested);
			freeBufferPtr( (KpGenericPtr_t)pTagIdsPassed);
		}
	}
	return status;

}
コード例 #9
0
PTErr_t
	makeForwardXformMono (	ResponseRecord_p	grayTRC,
							fut_p				theFut)
{
PTErr_t			PTErr = KCP_FAILURE;
KpInt32_t		futReturn, i1;
fut_otbldat_p	otblDat;
double			gamma;
fut_calcData_t	calcData;
KpUInt16_t		rrpData[2] = { 0, RRECORD_DATA_SIZE -1 };
ResponseRecord_t	rrt;
KpUInt16_t		*pCurveData = NULL;

	/* compute new table entries */
	calcData.chan = 0;				/* always uses 1st input chan */

	for (i1 = 0; i1 < FWD_MONO_OCHANS; i1++) {
		if (( ! IS_CHAN(theFut->chan[i1])) ||
			!fut_calc_gtblEx (theFut->chan[i1]->gtbl, fut_grampEx, &calcData) ||
			!fut_calc_otblEx (theFut->chan[i1]->otbl, otblFunc, NULL)) {
			goto ErrOut0;
		}
	}

	/* get address of the first output table */
	futReturn = fut_get_otbl (theFut, 0, &otblDat);
	if ((futReturn != 1) || (otblDat == (fut_otbldat_p)NULL)) {
		goto ErrOut0;
	}

	if (PARA_TYPE_SIG == grayTRC->TagSig)
	{
		pCurveData = (KpUInt16_p) allocBufferPtr (MFV_CURVE_TBL_ENT);	/* get memory for curve data */
		if (NULL == pCurveData) {
			return KCP_NO_MEMORY;
		}
		makeCurveFromPara (grayTRC->ParaFunction, grayTRC->ParaParams, pCurveData, MFV_CURVE_TBL_ENT);
		grayTRC->CurveCount = MFV_CURVE_TBL_ENT;
		grayTRC->CurveData = pCurveData;
	}
	/* setup the output table */
	switch (grayTRC->CurveCount)
	{
	case 0:
		/* setup the responseRecord struct */
		rrt.CurveCount = 2;
		rrt.CurveData = rrpData;

		/* make the output table */
		PTErr = calcOtblLSN (otblDat, &rrt);
		break;

	case 1:
		gamma = (double)grayTRC->CurveData[0] / SCALEDOT8;
		if (gamma <= 0.0) {
			goto ErrOut0;
		}

		/* make the output table */
		PTErr = calcOtblLS1 (otblDat, gamma);
		break;

	default:
		/* make the output table */
		makeMonotonic (grayTRC->CurveCount, grayTRC->CurveData);
		PTErr = calcOtblLSN (otblDat, grayTRC);
	}

GetOut:
	if (NULL != pCurveData) {
		freeBufferPtr (pCurveData);
	}
	return PTErr;


ErrOut0:
	PTErr = KCP_SYSERR_0;
	goto GetOut;
}
コード例 #10
0
PTErr_t
	TpReadHdr (	KpFd_p			fd,
				KpHandle_t FAR*	PTHdr,
				PTType_p		formatP)
{
PTErr_t		errnum;
fut_hdr_p	futHdr;
KpInt32_t	ret, hdrSize;

	hdrSize = (KpInt32_t)sizeof (fut_hdr_t);

	/* get header memory */
	futHdr = (fut_hdr_p) allocBufferPtr (hdrSize);
	if (futHdr == NULL) {
		errnum = KCP_NO_CHECKIN_MEM;
		goto ErrOut;
	}

	ret = Kp_read (fd, (KpGenericPtr_t)&futHdr->magic, sizeof (KpInt32_t));
	if (ret != 1) {
		errnum = KCP_INVAL_PT_BLOCK;
		goto ErrOut;
	}

#if !defined KCP_ICC_ONLY
	if ((futHdr->magic == FUT_CIGAM) || (futHdr->magic == FUT_MAGIC) ) {
		ret = fut_read_futhdr (fd, futHdr);	/* read in the header */
	}
	else {
#endif
#if defined (KPLSBFIRST)						/* swap bytes if necessary */
		Kp_swab32 ((KpGenericPtr_t)&futHdr->magic, 1);
#endif

		switch (futHdr->magic) {
		case PTTYPE_MFT1:	/* 8 bit matrix fut */
		case PTTYPE_MFT2:	/* 16 bit matrix fut */
			ret = fut_readMFutHdr (fd, futHdr);	/* read the matrix fut header */
			futHdr->idstr_len = 0;
			break;
		
		case PTTYPE_MA2B:
		case PTTYPE_MB2A:
			ret = fut_readMabFutHdr (fd, futHdr);	/* read the matrix fut header */
			futHdr->idstr_len = 0;
			break;
		
		default:
			errnum = KCP_INVAL_PT_BLOCK;	/* unknown type */
			goto ErrOut;
		}
#if !defined KCP_ICC_ONLY
	}
#endif

	if (ret != 1) {
		errnum = KCP_INVAL_PT_BLOCK;
		goto ErrOut;
	}

	futHdr->srcFormat = futHdr->magic;	/* remember original format */
	*formatP = futHdr->magic;			/* return type of PT */

	*PTHdr = unlockBufferPtr((KpGenericPtr_t)futHdr);	/* return handle to header info */
	if (*PTHdr == NULL) {
		errnum = KCP_MEM_UNLOCK_ERR;
		goto ErrOut;
	}

	return KCP_SUCCESS;

ErrOut:
	if (futHdr != NULL) {
		freeBufferPtr ((KpGenericPtr_t)futHdr);
	}

	return (errnum);

}
コード例 #11
0
/* fut_copy copies an existing fut.
 */
fut_p
	fut_copy (fut_p fut)
{
fut_p		new_fut;
KpInt32_t	i;
KpHandle_t	h;

	if ( ! IS_FUT(fut)) {
		return (0);
	}

				/* allocate basic fut_structure */
	new_fut = fut_alloc_fut ();
	if ( new_fut == FUT_NULL ) {
		return (FUT_NULL);
	}

				/* save handle before copying over old fut */
	h = new_fut->handle;

				/* copy over all data (including pointers */
	*new_fut = *fut;

				/* now copy back handle */
	new_fut->handle = h;

				/* copy id string */
	new_fut->idstr = 0;
/*	(void) fut_set_idstr (new_fut, fut->idstr); */

				/* copy input tables */
	for ( i=0; i<FUT_NICHAN; i++ ) {
		new_fut->itbl[i] = (IS_SHARED (fut->itbl[i])) ?
							fut_share_itbl (fut->itbl[i]) : fut_copy_itbl (fut->itbl[i]);
		new_fut->itblHandle[i] = getHandleFromPtr((KpGenericPtr_t)new_fut->itbl[i]);
	}

				/* copy output channels */
	for ( i=0; i<FUT_NOCHAN; i++ ) {
		new_fut->chan[i] = fut_copy_chan (fut->chan[i]);
		new_fut->chanHandle[i] = getHandleFromPtr((KpGenericPtr_t)new_fut->chan[i]);
	}

				/* now check that all copies were succesful */
	if ( new_fut->idstr == 0 && fut->idstr != 0 ) {
		goto ErrOut;
	}

	for ( i=0; i<FUT_NICHAN; i++ ) {
		if ( new_fut->itbl[i] == 0 && fut->itbl[i] != 0) {
			goto ErrOut;
		}
	}
	for ( i=0; i<FUT_NOCHAN; i++ ) {
		if ( new_fut->chan[i] == 0 && fut->chan[i] != 0) {
			goto ErrOut;
		}
	}

	for ( i=0; i<FUT_NMCHAN; i++ ) {	/* free extra reference tables */
		if (NULL != fut->mabInRefTblHandles[i])
		{
			new_fut->mabInTblEntries[i] = fut->mabInTblEntries[i];
			new_fut->mabInRefTbl[i] = (mf2_tbldat_p)
									allocBufferPtr (new_fut->mabInTblEntries[i] * sizeof (mf2_tbldat_t));
			KpMemCpy (new_fut->mabInRefTbl[i], fut->mabInRefTbl[i],
													new_fut->mabInTblEntries[i] * sizeof (mf2_tbldat_t));
			new_fut->mabInRefTblHandles[i] = getHandleFromPtr ((KpGenericPtr_t)new_fut->mabInRefTbl[i]);
		}

		if (NULL != fut->mabOutRefTblHandles[i])
		{
			new_fut->mabOutTblEntries[i] = fut->mabOutTblEntries[i];
			new_fut->mabOutRefTbl[i] = (mf2_tbldat_p)
									allocBufferPtr (new_fut->mabOutTblEntries[i] * sizeof (mf2_tbldat_t));
			KpMemCpy (new_fut->mabOutRefTbl[i], fut->mabOutRefTbl[i],
													new_fut->mabOutTblEntries[i] * sizeof (mf2_tbldat_t));
			new_fut->mabOutRefTblHandles[i] = getHandleFromPtr ((KpGenericPtr_t)new_fut->mabOutRefTbl[i]);
		}
	}

	return (new_fut);
	

ErrOut:
	fut_free (new_fut);
	return (FUT_NULL);
}
コード例 #12
0
/* 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;
}
コード例 #13
0
ファイル: spsys.c プロジェクト: fatman2021/myforthprocessor
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Allocate a block of memory.  The allocated block can be bigger
 *	than 64K.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	September 14, 1993
 *------------------------------------------------------------------*/
void FAR *SpMalloc (KpInt32_t Size)
{
	return allocBufferPtr (Size);
}
コード例 #14
0
/*---------------------------------------------------------------------------
 *  makeInverseXformFromMatrix -- make a fut of given gridsize from given
 *	matrix data for inverse transform (XYZ -> RGB); return status code
 *---------------------------------------------------------------------------
 */
PTErr_t
	makeInverseXformFromMatrix (LPMATRIXDATA	mdata,
								KpUInt32_t		interpMode,
								KpInt32_p		dim,
								fut_p			theFut)
{
PTErr_t			PTErr = KCP_SUCCESS;
ResponseRecord_p	rrp;
KpInt32_t		i;
fut_chan_p		theChan;
fut_gtbl_p		theGtbl;
fut_otbl_p		theOtbl;
mf2_tbldat_p	gtblDat[3], otblDat, prevOtblDat;
KpUInt16_t		prevGamma = 0, thisGamma;
double			fwdgamma, one[3];
double			offset[3] = {1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0};
KpUInt16_t		*pCurveData = NULL;

	for (i = 0; i < 3; i++) {
		if (!IS_CHAN(theChan = theFut->chan[i])
			|| !IS_GTBL(theGtbl = theChan->gtbl)
			|| ((gtblDat[i] = theGtbl->refTbl) == NULL) 	/* Get grid tables */
			|| !IS_OTBL(theOtbl = theChan->otbl)
			|| ((otblDat = theOtbl->refTbl) == NULL)) {		/* Get output table */
		   return KCP_INCON_PT;
		}
		
		if (theOtbl->refTblEntries != FUT_OUTTBL_ENT) return KCP_INCON_PT;

		 /* Get ResponseRecord:  */
		rrp = mdata->outResponse[i];
		if (NULL == rrp) {
			break;				/* must only have output tables */
		}
		if (PARA_TYPE_SIG == rrp->TagSig)
		{
			pCurveData = (KpUInt16_p) allocBufferPtr (MFV_CURVE_TBL_ENT*sizeof(KpUInt16_t));	/* get memory for curve data */
			if (NULL == pCurveData) {
				return KCP_NO_MEMORY;
			}
			makeCurveFromPara (rrp->ParaFunction, rrp->ParaParams, pCurveData, MFV_CURVE_TBL_ENT);
			rrp->CurveCount = MFV_CURVE_TBL_ENT;
			rrp->CurveData = pCurveData;
		}
		if ((rrp->CurveCount > 0) && (rrp->CurveData == (KpUInt16_p)NULL)) {
			PTErr = KCP_INCON_PT;
			goto ErrOut;
		}

		 /* Recompute output table:  */
		switch (rrp->CurveCount) {
		case 0:	/* linear response, with clipping */
			calcOtbl0 (otblDat);
			break;
			
		case 1:	/* power law */
			thisGamma = rrp->CurveData[0];
			if (prevGamma == thisGamma) {	/* same gamma, just copy table */
				memcpy (otblDat, prevOtblDat, sizeof (*otblDat) * FUT_OUTTBL_ENT);
			}
			else {					
				prevGamma = thisGamma;
				prevOtblDat = otblDat;

				fwdgamma = (double)thisGamma / SCALEDOT8;
				if (fwdgamma <= 0.0) {
					PTErr = KCP_INCON_PT;
					goto ErrOut;
				}
				calcOtbl1 (otblDat, fwdgamma);
			}
			break;
			
		default:	/* look-up table of arbitrary length */
			makeInverseMonotonic (rrp->CurveCount, rrp->CurveData);

			if (rrp->CurveCount == theOtbl->refTblEntries) {	/* ready-to-use look-up table */
				memcpy (otblDat, rrp->CurveData, sizeof (*otblDat) * rrp->CurveCount);
			}
			else {
				PTErr = calcOtblN (otblDat, rrp, interpMode);
				if (PTErr != KCP_SUCCESS) {
					PTErr = KCP_INCON_PT;
					goto ErrOut;
				}
			}

			break;
		}
	}

	/* Compute inverse matrix (XYZ -> RGB):  */
	one[0] = one[1] = one[2] = 1.0;			/* arbitrary vector */

	 /* replaces matrix with inverse */
	if (solvemat (3, mdata->matrix, one) != 0) {
		PTErr = KCP_INCON_PT;
		goto ErrOut;
	}

	/* Rescale given matrix by factor of 3 for extended range:  */
	for (i = 0; i < 3; i++) {
		KpInt32_t	j;

		for (j = 0; j < 3; j++) {
			mdata->matrix[i][j] /= 3.0;
		}
	}

    /* Replace grid tables:  */
	calcGtbl3 (gtblDat, dim, mdata->matrix, offset);	/* with offset */

ErrOut:
	if (NULL != pCurveData) {
		freeBufferPtr (pCurveData);
	}
	return PTErr;
}
コード例 #15
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Return the Tag from the profile.
 *
 * AUTHOR
 * 	doro
 *
 * DATE CREATED
 *	March 12, 2002
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileLoadTagEx(
    char                   *Filename,
    SpFileProps_t          *Props,
    SpTagId_t               TagId,
    SpTagValue_t            FAR *Value)
{
    SpHeader_t       Header;
    SpHeader_t       *HeaderPtr;
    SpHugeBuffer_t   BufferAddress, TagAddress;
    SpStatus_t       Status = SpStatSuccess;
    KpFileId         FD;
    KpFileProps_t    fileProps;
    char             name[MAX_PATH];
    KpUInt32_t       FilePosition = HEADER_SIZE;
    KpInt32_t       Read_Amount  = sizeof(KpInt32_t);
    KpInt32_t       i, TagArraySize, TagBufferSize;
    SpTagRecord_t   *TagArray;

    if (!SpIsICCProfile(Filename, Props))
        return (SpStatBadProfile);

    strcpy (name, Filename);

    /* Need Header in case we are requesting a Named Color */
    HeaderPtr = (SpHeader_t *)NULL;
    if (TagId == SpTagNamedColor)
    {
        HeaderPtr = &Header;
        Status = SpProfileLoadHeader(name, Props, HeaderPtr);
    }
    if (Status == SpStatSuccess)
    {
        /* Set up for failure - yes I know I'm negative */
        Status = SpStatFileNotFound;

#if defined (KPMAC)
        SpCvrtSpFileProps(Props, &fileProps);
#endif
        if (KpFileOpen(Filename, "r", &fileProps, &FD)) /* 0 = not opened */
        {
            if (KpFilePosition(FD, FROM_START, FilePosition))
            {

                Status = SpStatFileReadError;
                /* Read TagArraySize into Buffer  */
                if (KpFileRead(FD, &TagArraySize, &Read_Amount))
                {
#if defined (KPLSBFIRST)
                    /* If we are on a little endian machine we need to do byte swap	*/
                    Kp_swab32 (&TagArraySize, 1);
#endif
                    TagBufferSize = TagArraySize * 3 * 4;  /* each entry is 3*4 bytes */
                    BufferAddress = allocBufferPtr(TagBufferSize);
                    if (BufferAddress != NULL)
                    {
                        if (KpFileRead(FD, BufferAddress, &TagBufferSize))
                        {
#if defined (KPLSBFIRST)
                            /* If we are on a little endian machine we need to do byte swap	*/
                            Kp_swab32 (BufferAddress, TagBufferSize / sizeof (KpInt32_t));
#endif
                            TagArray = BufferAddress;
                            Status = SpStatTagNotFound;
                            for (i = 0; i < TagArraySize; i++)
                            {
                                if (TagId == (SpTagId_t)TagArray[i].Id)
                                {
                                    Status = SpStatMemory;
                                    TagAddress = allocBufferPtr(TagArray[i].Size);
                                    if (TagAddress != NULL)
                                    {
                                        if (KpFilePosition(FD, FROM_START, TagArray[i].Offset))
                                        {
                                            Read_Amount = TagArray[i].Size;
                                            if (KpFileRead(FD, TagAddress, &Read_Amount))
                                            {
                                                Status = SpTagToPublic(HeaderPtr,   TagId,
                                                                       TagArray[i].Size,
                                                                       TagAddress,  Value);
                                            }
                                        }
                                        freeBufferPtr(TagAddress);
                                    } else
                                    {
                                        Status = SpStatMemory;
                                        break;
                                    }
                                }
                            }
                        }
                        freeBufferPtr(BufferAddress);
                    } else /* Buffer Address != 0 */
                        Status = SpStatMemory;
                }
            }
            /* Close File */
            KpFileClose(FD);
        }
    }
    return Status;

}
コード例 #16
0
/*-------------------------------------------------------------------
 *  init_xfer -- initialize the transfer tables by transferring coarse
 *			control points from an ICC ResponseRecord
 *			and interpolating the fine tables from them;
 *			returns +1 for success, -1 for failure to
 *			allocate memory for coarse table
 *-------------------------------------------------------------------
 */
PTErr_t
	init_xfer (	xfer_p				xferp,
				ResponseRecord_p	rrp)
{
PTErr_t		PTErr = KCP_SUCCESS;
double		val;			/* input variables */
KpInt32_t	numcoarse;		/* number of input control points */
double_p	coarse[2];		/* storage for control points */
KpInt32_t	i;			/* control-point index */
KpInt32_t	hint;
KpUInt16_t	*pCurveData = NULL;

     /* Verify inputs:  */
	if (xferp == (xfer_p)NULL)	return KCP_SYSERR_0;
	if (rrp == (ResponseRecord_p)NULL)	return KCP_SYSERR_0;
	
	if (PARA_TYPE_SIG == rrp->TagSig)
	{
		pCurveData = (KpUInt16_p) allocBufferPtr (MFV_CURVE_TBL_ENT*sizeof(KpUInt16_t));	/* get memory for curve data */
		if (NULL == pCurveData) {
			return KCP_NO_MEMORY;
		}
		makeCurveFromPara (rrp->ParaFunction, rrp->ParaParams, pCurveData, MFV_CURVE_TBL_ENT);
		rrp->CurveCount = MFV_CURVE_TBL_ENT;
		rrp->CurveData = pCurveData;
	}
	if (rrp->CurveCount < 2) {
		PTErr = KCP_SYSERR_0;
		goto ErrOut;
	}
	if (rrp->CurveData == (KpUInt16_p)NULL) {
		PTErr = KCP_SYSERR_0;
		goto ErrOut;
	}
	   
     /* Allocate space for coarse tables:  */
	numcoarse = rrp->CurveCount - 1;	/* skip zero entry to avoid infinity in logarithm */
	coarse[0] = (double_p)ALLOC (numcoarse, sizeof(double));
	if (coarse[0] == NULL)
	{
		PTErr = KCP_NO_MEMORY;
		goto ErrOut;
	}
	coarse[1] = (double_p)ALLOC (numcoarse, sizeof(double));
	if (coarse[1] == NULL)
	{
	   DALLOC (coarse[0]);	/* release storage */
		PTErr = KCP_NO_MEMORY;
		goto ErrOut;
	}

     /* Build coarse tables from ResponseRecord:  */
	for (i = 0; i < numcoarse; i++)
	{
	   val = (double)(i + 1) / (double)numcoarse;	/* skip zero to avoid infinite log */
	   coarse[0][i] = -log10 (val);
	   val = (double)rrp->CurveData[i + 1] / SCALEDOT16;
	   val = MAX (val, 1.0e-12);			/* clip to avoid infinite log */
	   coarse[1][i] = -log10 (val);
	}

     /* Build fine tables by interpolating in coarse tables:  */
	hint = 1;
	for (i = 0; i < NUMFINE; i++)				/* spaced code values */
	{
	   double	code;

	   code = (double)i * 2.4 / (double)(NUMFINE - 1);	/* equally spaced in [0, 2.4] */
	   xferp->nonlinear[i] = code;
	   xferp->linear[i] = f4l (code, coarse[0], coarse[1], numcoarse, &hint);
	}

     /* Delete coarse tables:  */
	DALLOC (coarse[0]);
	DALLOC (coarse[1]);

ErrOut:
	if (NULL != pCurveData) {
		freeBufferPtr (pCurveData);
	}
	return PTErr;
}
コード例 #17
0
ファイル: filemap.c プロジェクト: fatman2021/myforthprocessor
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Unmap an entire file. (WIN32 Version)
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	November 9, 1993
 *------------------------------------------------------------------*/
KpInt32_t KpUnMapFile (KpMapFile_t FAR *MapFileCtl)
{
	int	Status;

	Status = KCMS_IO_SUCCESS;
	if (!UnmapViewOfFile (MapFileCtl->Ptr))
		Status = KCMS_IO_ERROR;

	if (!CloseHandle (MapFileCtl->hMapObject))
		Status = KCMS_IO_ERROR;

#if defined(_M_IA64)
	if (!CloseHandle (MapFileCtl->hFile)) {
#else /* non-64-bit case */
	if (_lclose (MapFileCtl->hFile)) {
#endif /* defined(_M_IA64) */
		Status = KCMS_IO_ERROR;
	}

	return Status;
}

#else


/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Map an entire file.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	November 9, 1993
 *------------------------------------------------------------------*/
void FAR *KpMapFileEx (
				KpChar_p		FileName,
				KpFileProps_t	FAR *FileProps,
				KpChar_p		Mode,
				KpMapFile_t	FAR *MapFileCtl)
{
/* validate mode */
	switch (*Mode) {
	case 'R':
	case 'r':
#if 0
	case 'w':
#endif
		break;
	
	default:
		return NULL;
	}

/* get the size of the file */
	if (!KpFileSize (FileName, FileProps, &MapFileCtl->NumBytes))
		return NULL;

/* allocate buffer to hold file */
	MapFileCtl->Ptr = allocBufferPtr (MapFileCtl->NumBytes);
	if (NULL == MapFileCtl->Ptr)
		return NULL;

/* open the file */
	if (!KpFileOpen (FileName, Mode, FileProps, &MapFileCtl->Fd)) {
		freeBufferPtr (MapFileCtl->Ptr);
		return NULL;
	}

/* read file into the buffer */
	if (!KpFileRead (MapFileCtl->Fd, MapFileCtl->Ptr, &MapFileCtl->NumBytes)) {
		freeBufferPtr (MapFileCtl->Ptr);
		KpFileClose (MapFileCtl->Fd);
		return NULL;
	}

/* done with file, close it */
	if ('r' == *Mode) {
		KpFileClose (MapFileCtl->Fd);
		MapFileCtl->Fd = -1;
	}
	MapFileCtl->Mode = *Mode;

	return MapFileCtl->Ptr;
}


/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Map an entire file. (non-win32 version)
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	November 9, 1993
 *------------------------------------------------------------------*/
void FAR *KpMapFile (
				KpChar_p		FileName,
				ioFileChar	FAR *FileProps,
				KpChar_p		Mode,
				KpMapFile_t	FAR *MapFileCtl)
{
KpFileProps_t	kpFileProps, *kpFilePropsPtr;

	/* convert FileProps to KpFileProps_t and call
	   KpMapFileEx */
#if defined (KPMAC) || defined (KPMSMAC)
	if (FileProps != NULL) {
		kpFileProps.vRefNum = FileProps->vRefNum;
		kpFileProps.dirID= 0;
		strncpy(kpFileProps.fileType, FileProps->fileType, 5);
		strncpy(kpFileProps.creatorType, FileProps->creatorType, 5);
	}
	else {
		kpFileProps.vRefNum = 0;
		kpFileProps.dirID= 0;
		strncpy(kpFileProps.fileType, "    ", 5);
		strncpy(kpFileProps.creatorType, "    ", 5);
	}
	kpFilePropsPtr = &kpFileProps;
#else
	kpFilePropsPtr = FileProps;
#endif
	return (KpMapFileEx (FileName, kpFilePropsPtr, Mode, MapFileCtl) );
}