/*-------------------------------------------------------------------- * DESCRIPTION * Returns KPTRUE if seems to be ICC Formatted Profile * private function * AUTHOR * doro * * DATE CREATED * August 9, 1996 *------------------------------------------------------------------*/ KpBool_t KSPAPI SpIsICCProfile( char *Filename, SpFileProps_t *Props) { KpUInt32_t ProfileSize; KpUInt32_t ProfileCode = 0; SpStatus_t Status = SpStatBadProfile; KpFileId FD; char *name; KpUInt32_t Read_Size_OK, Read_Code_OK = 0; KpInt32_t Read_Amount = 4; KpFileProps_t fileProps; KpBool_t IsICC = KPFALSE; char ReadBufferArray[8]; char *ReadBuffer; name = Filename; #if defined (KPMAC) SpCvrtSpFileProps(Props, &fileProps); #endif if (KpFileOpen(name, "r", &fileProps, &FD)) /* 0 = not opened */ { /* Read HEADER_SIZE into Buffer */ ReadBuffer = ReadBufferArray; Read_Size_OK = KpFileRead(FD, ReadBuffer, &Read_Amount); ProfileSize = SpGetUInt32(&ReadBuffer); if (KpFilePosition(FD, FROM_START, 36)) { ReadBuffer = ReadBufferArray; Read_Code_OK = KpFileRead(FD, ReadBuffer, &Read_Amount); ProfileCode = SpGetUInt32(&ReadBuffer); } /* Close File */ KpFileClose(FD); if ((Read_Size_OK) && (ProfileSize > HEADER_SIZE)) { if ((Read_Code_OK) && (ProfileCode == (0x61637370))) IsICC = KPTRUE; } } return (IsICC); }
SpStatus_t SpProfileCheckSize( void FAR *Buffer, KpUInt32_t size) { char KPHUGE *Ptr = (char KPHUGE *)Buffer; if (size < sizeof(KpUInt32_t)) { return SpStatBadProfile; } else if (size != SpGetUInt32(&Ptr)) { return SpStatBadProfile; } return SpStatSuccess; }
/*-------------------------------------------------------------------- * DESCRIPTION (Public) * Load a profile from a file. * * AUTHOR * doro * * DATE CREATED * December 5, 1995 *------------------------------------------------------------------*/ SpStatus_t KSPAPI SpProfileLoadProfile ( SpCallerId_t CallerId, KpChar_t *FileName, SpFileProps_t *Props, SpProfile_t FAR *Profile) { KpMapFile_t MapFileCtl; KpFileProps_t props; SpStatus_t Status; char KPHUGE *Ptr; KpInt32_t ProfileSize; #if defined (KPMAC) /* Convert file information into useable form */ SpCvrtSpFileProps(Props, &props); #endif /* Map the file */ if (NULL == KpMapFileEx (FileName, &props, "r", &MapFileCtl)) return SpStatFileNotFound; Ptr = (char *)MapFileCtl.Ptr; ProfileSize = (KpInt32_t)SpGetUInt32 (&Ptr); if (ProfileSize > MapFileCtl.NumBytes) { KpUnMapFile (&MapFileCtl); return SpStatBadProfile; } /* Load the profile */ Status = SpProfileLoadFromBuffer (CallerId, MapFileCtl.Ptr, Profile); /* Unmap the file */ KpUnMapFile (&MapFileCtl); /* Remember the file name */ if (SpStatSuccess == Status) { Status = SpProfileSetName (*Profile, FileName, Props); if (SpStatSuccess != Status) SpProfileFree (Profile); } return Status; }
/*-------------------------------------------------------------------- * DESCRIPTION * Convert profile file to internal format. * * AUTHOR * lsh * * DATE CREATED * October 18, 1993 *------------------------------------------------------------------*/ SpStatus_t SpProfileLoadFromBufferImp ( SpProfileData_t FAR *ProfileData, char KPHUGE *BaseAddr) { SpStatus_t Status; char KPHUGE *Ptr; KpUInt32_t ProfileSize; KpUInt32_t TagDataHeader; KpUInt32_t Offset; KpUInt32_t Count; KpUInt32_t i; SpTagId_t TagId; KpUInt32_t TagOffset; KpUInt32_t TagSize; /* validate that atleast the first long of the buffer is readable */ if (BaseAddr == NULL) return SpStatBadBuffer; /* get the long, this is the size of the profile data */ Ptr = BaseAddr; ProfileSize = SpGetUInt32 (&Ptr); /* validate that the entire buffer is readable */ if (BaseAddr == NULL) return SpStatBadBuffer; /* convert the header to public form */ Status = SpHeaderToPublic (BaseAddr, ProfileSize, &ProfileData->Header); if (SpStatSuccess != Status) return Status; TagDataHeader = 128; Ptr = BaseAddr + TagDataHeader; /* check that the offset to the Tag Data is inside the file */ if (ProfileSize < TagDataHeader + 4) return SpStatOutOfRange; /* get number of tags */ Offset = TagDataHeader + sizeof (KpUInt32_t); if (ProfileSize < Offset) return SpStatBadProfile; Ptr = BaseAddr + TagDataHeader; Count = SpGetUInt32 (&Ptr); /* validate that tag directory is readable */ if (ProfileSize < Offset + Count * 3 * sizeof (KpUInt32_t)) Status = SpStatBadProfileDir; /* Set the Profile Size and initialize the Profile Changed Flag */ ProfileData->ProfileSize = ProfileSize; ProfileData->ProfChanged = KPFALSE; /* build tag directory */ Status = SpStatSuccess; for (i = 0; (SpStatSuccess == Status) && (i < Count); i++) { TagId = (SpTagId_t) SpGetUInt32 (&Ptr); TagOffset = SpGetUInt32 (&Ptr); if (ProfileSize < TagOffset) return SpStatBadProfileDir; /* The following two lines are removed to allow for reading of certain ICC Profiles that don't meet the specification. This has been a continual support problem and we've decided to go with the other CMM vendors and loosen our criteria */ /* if (TagOffset & 3) return SpStatBadProfileDir; */ TagSize = SpGetUInt32 (&Ptr); /* Casting one of the items of the sum to the 64-bit type to * force the whole expression be calculated in 64-bit. That * protects the check from overflowing */ if (ProfileSize < (jlong)TagOffset + TagSize) return SpStatBadProfileDir; Status = SpTagDirEntryAdd (ProfileData, TagId, TagSize, BaseAddr + TagOffset); } return Status; }