Exemple #1
0
/* fut_free_otbl_p
		This function is passed a fut_otbl_t pointer
		and handle.	If the ref count is zero, the table and
		the fut_otbl_t is freed.	Otherwise the ref count is 
		decremented and the lock state of the fut_otbl_t
		is returned to it's state on entry.
*/
static void
	fut_free_otbl_p (	fut_otbl_p	otblPtr,
						KpHandle_t	otblHdl)
{
fut_otbl_p	otbl = otblPtr;

	if (otblHdl == NULL) {
		return;
	}

	if (otbl == NULL) {		/* otbl is unlocked on entry */
		otbl = lockBuffer(otblHdl);
	}

	if (IS_OTBL(otbl)) {
		if (otbl->ref == 0) {	/* last reference being freed */
			freeBuffer(otbl->tblHandle);
			otbl->magic = 0;
			freeBufferPtr ((KpGenericPtr_t)otbl);
		}
		else {
			if (otbl->ref > 0) {	/* still other references */
				otbl->ref--;	/* leave in original lock state */
				if (otblPtr == NULL) {
					unlockBuffer(otblHdl);
				}
			}
		}
	}
}
Exemple #2
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Delete a profile. If there is a file associated with the profile,
 *	it is also deleted.
 *
 * AUTHOR
 * 	lsh & mlb
 *
 * DATE CREATED
 *	May 4, 1995
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileDelete (
    SpProfile_t FAR *Profile)
{
    KpChar_t		*fileName;
    SpProfileData_t	FAR *ProfileData;
    KpFileProps_t		Props;

    /* convert profile handle to data pointer */
    ProfileData = SpProfileLock (*Profile);
    if (NULL == ProfileData)
        return SpStatBadProfile;

    /* lock FileName handle and return  ptr */
    fileName = (char *) lockBuffer (ProfileData->FileName);

#if defined (KPMAC)
    /* Convert SpIOFileChar_t to KpFileProps_t */
    SpCvrtSpFileProps (&(ProfileData->Props), &Props);
#endif

    /* delete associated file name */
    if (NULL != fileName)
        KpFileDelete (fileName, &Props);

    /* unlock handles */
    unlockBuffer (ProfileData->FileName);
    SpProfileUnlock (*Profile);
    return SpProfileFree (Profile);
}
Exemple #3
0
/* fut_free_gtbl_p
		This function is passed a fut_gtbl_t pointer
		and handle.	If the ref count is zero, the table and
		the fut_gtbl_t is freed.  Otherwise the ref count is 
		decremented and the lock state of the fut_gtbl_t
		is returned to it's state on entry.
*/
static void
	fut_free_gtbl_p (	fut_gtbl_p	gtblP,
						KpHandle_t	gtblHdl)
{
fut_gtbl_p	gtbl = gtblP;

	if (gtblHdl == NULL) {
		return;
	}

	if (gtbl == NULL) {				/* gtbl is unlocked on entry */
		gtbl = lockBuffer(gtblHdl);
	}
	
	if (IS_GTBL(gtbl)) {
		if (gtbl->ref == 0) {
			fut_free_gtbl(gtbl);	/* last reference being freed */
		}
		else {
			if (gtbl->ref > 0) {	/* still other references, leave in original lock state */
				gtbl->ref--;
				if (gtblP == NULL) {
					unlockBuffer(gtblHdl);
				}
			}
		}
	}
}
Exemple #4
0
/* fut_free_itbl_list_p
		This function is passed a list of fut_itbl_t pointers
		and handles.	If the ref count is zero, the table and
		the fut_itbl_t is freed.	Otherwise the ref count is 
		decremented and the lock state of the fut_itbl_t
		is returned to it's state on entry.
*/
static void
	fut_free_itbl_list_p (	fut_itbl_p FAR *	itbl_list,
							KpHandle_t FAR *	itblHdl_list)
{
KpInt32_t	i;
fut_itbl_p	itbl;

	if ((itbl_list == NULL) || (itblHdl_list == NULL)) {
		return;
	}

	for (i = 0; i < FUT_NICHAN; i++) {
		itbl = itbl_list[i];
		if (itbl == NULL) {
			itbl = lockBuffer (itblHdl_list[i]);
		}

		if (IS_ITBL(itbl)) {
			if (itbl->ref == 0) {
				fut_free_itbl (itbl);	/* last reference being freed */
				itbl_list[i] = NULL;
				itblHdl_list[i] = NULL;
			}
			else {
				if ( itbl->ref > 0 ) {	/* still other references */
					itbl->ref--;
					if (itbl_list[i] == NULL) {	/* leave in original lock state */
						unlockBuffer(itblHdl_list[i]);
					}
				}
			}
		}
	}
}
Exemple #5
0
/*--------------------------------------------------------------------
 * DESCRIPTION	(Public)
 *	Return the name of the currently associated file.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	September 20, 1993
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileGetDiskName (
    SpProfile_t		Profile,
    size_t			BufferSize,
    KpChar_t		*Buffer,
    SpIOFileChar_t	*Props)
{
    char				FAR *fileName;
    SpProfileData_t		FAR *ProfileData;

    /* convert profile handle to data pointer */
    ProfileData = SpProfileLock (Profile);
    if (NULL == ProfileData)
        return SpStatBadProfile;

    /* lock FileName handle and return  ptr */
    fileName = (char *) lockBuffer (ProfileData->FileName);

    /* check for case of no file name */
    if (NULL == fileName) {
        *Buffer = '\0';
        SpProfileUnlock (Profile);
        return SpStatNoFileName;
    }

    /* check for buffer large enough */
    if (BufferSize < strlen (fileName) + 1) {
        unlockBuffer (ProfileData->FileName);
        SpProfileUnlock (Profile);
        return SpStatBufferTooSmall;
    }

    strcpy (Buffer, fileName);

    /* Get file properties */
#if defined (KPMAC)
    SpProfSetSpFileData (&(ProfileData->Props), Props);
#endif

    /* unlock handles */
    unlockBuffer (ProfileData->FileName);
    SpProfileUnlock (Profile);

    return SpStatSuccess;
}
	void DepthBuffer32::Clear( boost::uint32_t value )
	{
		boost::uint32_t* bufferPtr = NULL;

		if( lockBuffer( bufferPtr ) )
		{
			// Loop unrolling via Duff's device
			// http://en.wikipedia.org/wiki/Duff's_device
			duff_copy8( value, bufferPtr, getSize() );
			
			unlockBuffer();
		}
	}
Exemple #7
0
/*--------------------------------------------------------------------
 * DESCRIPTION	(Private -- phase out 5/4/95)
 *	Return the name of the currently associated file.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	September 20, 1993
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileGetFileName (
    SpProfile_t		Profile,
    size_t			BufferSize,
    char			FAR *Buffer)
{
    char				FAR *fileName;
    SpProfileData_t		FAR *ProfileData;

    /* convert profile handle to data pointer */
    ProfileData = SpProfileLock (Profile);
    if (NULL == ProfileData)
        return SpStatBadProfile;

    /* lock FileName handle and return  ptr */
    fileName = (char *) lockBuffer (ProfileData->FileName);

    /* check for case of no file name */
    if (NULL == fileName) {
        *Buffer = '\0';
        SpProfileUnlock (Profile);
        return SpStatNoFileName;
    }

    /* check for buffer large enough */
    if (BufferSize < strlen (fileName) + 1) {
        unlockBuffer (ProfileData->FileName);
        SpProfileUnlock (Profile);
        return SpStatBufferTooSmall;
    }

    strcpy (Buffer, fileName);

    /* unlock handles */
    unlockBuffer (ProfileData->FileName);
    SpProfileUnlock (Profile);

    return SpStatSuccess;
}
Exemple #8
0
	void String8::setPathName(const char* name, size_t len)
	{
		char* buf = lockBuffer(len);

		memcpy(buf, name, len);

		// remove trailing path separator, if present
		if (len > 0 && buf[len - 1] == OS_PATH_SEPARATOR)
			len--;

		buf[len] = '\0';

		unlockBuffer(len);
	}
Exemple #9
0
/* TpWriteHdr writes the header of a fut to an external memory block.
 */
PTErr_t
	TpWriteHdr(	KpFd_p			fd,
				PTType_t	format,
				KpHandle_t	PTHdr,
				KpInt32_t		attrSize)
{
PTErr_t errnum = KCP_SUCCESS;
fut_hdr_p futHdr;

	switch (format) {
	case PTTYPE_FUTF:	/* get buffer pointer */
		futHdr = (fut_hdr_p)lockBuffer (PTHdr);
		if (futHdr == NULL) {
			errnum = KCP_MEM_LOCK_ERR;
			return errnum;
		}

		futHdr->idstr_len = attrSize;		/* insert size of attributes */
	
		if (fut_write_hdr (fd, futHdr) == 0) {	/* and write out the header */
			errnum = KCP_PT_HDR_WRITE_ERR;
		}

		if ( ! unlockBuffer (PTHdr)) {
			errnum = KCP_MEM_UNLOCK_ERR;
		}

		break;

	case PTTYPE_MFT1:
	case PTTYPE_MFT2:
	case PTTYPE_MFT2_VER_0:
		errnum = KCP_SUCCESS;
		break;

	case PTTYPE_MAB1:
	case PTTYPE_MAB2:
	case PTTYPE_MBA1:
	case PTTYPE_MBA2:
		errnum = KCP_SUCCESS;
		break;

	default:
		errnum = KCP_INVAL_PTTYPE;
		break;
	}
	
	return errnum;
}
Exemple #10
0
	String8& String8::convertToResPath()
	{
#if OS_PATH_SEPARATOR != RES_PATH_SEPARATOR
		size_t len = length();
		if (len > 0) {
			char * buf = lockBuffer(len);
			for (char * end = buf + len; buf < end; ++buf) {
				if (*buf == OS_PATH_SEPARATOR)
					*buf = RES_PATH_SEPARATOR;
			}
			unlockBuffer(len);
		}
#endif
		return *this;
	}
// ***************************************************************************
void				CVegetableVBAllocator::deleteVertexBufferHard()
{
	// must unlock VBhard before.
	unlockBuffer();

	// test (refptr) if the object still exist in memory.
	if(_VBHard.getNumVertices()!=0)
	{
		// A vbufferhard should still exist only if driver still exist.
		nlassert(_Driver!=NULL);

		// delete it from driver.
		_VBHard.deleteAllVertices ();
	}

}
// ***************************************************************************
void			CVegetableVBAllocator::lockBuffer()
{
	// force unlock
	unlockBuffer();

	// need to lock only if the VBHard is created
	if(_VBHardOk)
	{
		// lock the VBHard for writing
		_VBHard.lock(_VBAHard);
		_AGPBufferPtr=(uint8*)_VBAHard.getVertexCoordPointer();

		// lock the Input VertexBuffer for reading
		_VBSoft.lock(_VBASoft);
		_RAMBufferPtr=(const uint8*)_VBASoft.getVertexCoordPointer();
	}
}
Exemple #13
0
/*--------------------------------------------------------------------
 * DESCRIPTION	(Public)
 *	Set the name of the file to associate with the profile.
 *	If the Name is NULL no file will be associated with the profile.
 *
 * AUTHOR
 * 	lsh & mlb
 *
 * DATE Copied
 *	November 15, 1995
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileSetName (
    SpProfile_t		Profile,
    KpChar_t		*FileName,
    SpFileProps_t	*Props)
{
    char			FAR *fileName;
    SpProfileData_t		FAR *ProfileData;
    SpStatus_t		status;

    /* convert profile handle to data pointer */
    ProfileData = SpProfileLock (Profile);
    if (NULL == ProfileData)
        return SpStatBadProfile;

    /* Free current FileName if one is there */
    if (ProfileData->FileName != NULL)
    {
        if (ProfileData->TagArray == NULL)
            status = SpProfilePopTagArray(ProfileData);

        freeBuffer(ProfileData->FileName);
    }

    /* create the FileName handle */
    ProfileData->FileName = allocBufferHandle (strlen (FileName) + 1);
    if (ProfileData->FileName == NULL)
        return SpStatMemory;

    /* lock FileName handle and return ptr */
    fileName = (char *) lockBuffer (ProfileData->FileName);
    if (fileName == NULL)
        return SpStatMemory;

    /* copy text data into the newly allocated space */
    strcpy (fileName, FileName);

    /* Copy props information into internal profile data structure */
#if defined (KPMAC)
    SpProfSetSpFileProps (Props, &(ProfileData->Props));
#endif

    /* unlock handles */
    unlockBuffer (ProfileData->FileName);
    SpProfileUnlock (Profile);
    return SpStatSuccess;
}
Exemple #14
0
/* unlock header and data of a PT
 */
PTErr_t
	unlockPT (	KpHandle_t	PTHdr,
				fut_p		fut)
{
PTErr_t errnum = KCP_SUCCESS;

	if (fut_unlock_fut (fut) == NULL) {
		errnum = KCP_PTERR_1;
	}
	else {
		if ( ! unlockBuffer (PTHdr)) {
			errnum = KCP_MEM_UNLOCK_ERR;
		}
	}

	return errnum;
}
Exemple #15
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Iterate over all the tags in a profile.  Call user supplied
 *	function with the Id of each tag.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	July 7, 1994
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpTagIter (
				SpProfile_t		Profile,
				SpTagIter_t		TagIterFunc,
				void			FAR *Data)
{
	KpInt32_t		index;
	SpProfileData_t		FAR *ProfileData;
	SpTagDirEntry_t	FAR *tagArray;
	SpStatus_t			Status;

/* convert profile handle to pointer to locked memory */
	ProfileData = SpProfileLock (Profile);
	if (NULL == ProfileData)
		return SpStatBadProfile;

	Status = SpDoIter ( TagIterFunc, SpIterInit, NULL, 0, Data);

	/* Check if Profile found via Search function */
	if (ProfileData->TagArray == NULL)
		/* If so, it needs the Tag Array Loaded */
		SpProfilePopTagArray(ProfileData);

	for (index = 0; (index < ProfileData->TotalCount) && (Status == SpStatSuccess); index++)
	{
		/* User Callback Function could unlock since the
		   Profile is available, so lock before calling */
		/* lock TagArray handle and return ptr */
		tagArray = (SpTagDirEntry_t FAR *) 
				lockBuffer (ProfileData->TagArray);

		/* call users function ONLY IF VALID ENTRY */	
		if (tagArray[index].TagDataSize != -1)
			Status = SpDoIter(TagIterFunc,
					SpIterProcessing, 
					Profile, 
					tagArray[index].TagId, 
					Data);
	}

	unlockBuffer (ProfileData->TagArray);

	SpDoIter ( TagIterFunc, SpIterTerm, NULL, 0, Data);

	SpProfileUnlock (Profile);
	return Status;
}
Exemple #16
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Convert Profile handle to pointer to locked profile data.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	September 20, 1993
 *------------------------------------------------------------------*/
SpProfileData_t	FAR *SpProfileLock (SpProfile_t Profile)
{
	SpProfileData_t	FAR *ProfileData;

	ProfileData = lockBuffer ((KcmHandle) Profile);
	if (NULL != ProfileData) {
#if defined(KPMAC)
		/* increment the lock counter */
		ProfileData->LockCount++;
#endif
		if (SpProfileDataSig != ProfileData->Signature) {
			unlockBuffer ((KcmHandle) Profile);
			return NULL;
		}
	}
	return ProfileData;
}
Exemple #17
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 * This function inverts the input tables of a PT
 *
 * AUTHOR
 * PGT
 *
 * DATE CREATED
 * May 11, 1994
 *--------------------------------------------------------------------*/
static PTErr_t
	InvertInputTables (	PTRefNum_t	refNum,
						KpInt32_t	numOutChan,
						KpInt32_t	FAR *numInVar)
{
KpInt32_t	in, out, k;
PTErr_t		cpStatus;
KcmHandle	refTblHandle;
mf2_tbldat_p	refTbl;
mf2_tbldat_t	refTblTemp;
KcmHandle	tblList[FUT_NOCHAN * FUT_NICHAN];
KpInt32_t	numTbls, refTblEntries;

	/* Get each table, invert if not already inverted */
	cpStatus = KCP_SUCCESS;
	for (out = 0, numTbls = 0; (out < numOutChan) && (cpStatus == KCP_SUCCESS); ++out) {
		for (in = 0; (in < numInVar [out]) && (cpStatus == KCP_SUCCESS); ++in) {
			cpStatus = getRefTbl (FUT_IMAGIC, refNum, in, out, &refTblHandle, &refTblEntries);
			if (cpStatus == KCP_NO_INTABLE)	{	/* no input tbl, ignore */
				cpStatus = KCP_SUCCESS;
			}
			else {
				if ((cpStatus == KCP_SUCCESS) && (UniqueTable (refTblHandle, tblList, numTbls))) {
					refTbl = lockBuffer (refTblHandle);
					if (refTbl != NULL) {
						tblList [numTbls++] = refTblHandle;	/* save address to avoid multiple inversion */

						for (k = 0; k < refTblEntries/2; ++k) {		/* invert the table */
							refTblTemp = refTbl [k];				/* by reversing the order of the entries */
							refTbl [k] = refTbl [refTblEntries-1-k];
							refTbl [refTblEntries-1-k] = refTblTemp;
						}

						unlockBuffer (refTblHandle);
					}
					else {
						cpStatus = KCP_MEM_LOCK_ERR;
					}
				}
			}
		}
	}
	
	return cpStatus;
}
void GraphicsDeviceGL_1_3::drawVirtualScreen()
{
	glViewport( m_virtualViewport[0], m_virtualViewport[1], m_virtualViewport[2], m_virtualViewport[3] );

	//update the video memory framebuffer.
	lockBuffer();
		if (m_writeFrame > m_renderFrame)
		{
			m_videoFrameBuffer->update( m_frameWidth, m_frameHeight, m_frameBuffer_32bpp[m_writeBufferIndex] );
		}
		m_renderFrame = m_writeFrame;
	unlockBuffer();

	enableBlending(false);
	drawFullscreenQuad(m_videoFrameBuffer);

	glViewport( m_fullViewport[0], m_fullViewport[1], m_fullViewport[2], m_fullViewport[3] );
}
Exemple #19
0
	void String8::toUpper(size_t start, size_t length)
	{
		const size_t len = size();
		if (start >= len) {
			return;
		}
		if (start + length > len) {
			length = len - start;
		}
		char* buf = lockBuffer(len);
		buf += start;
		while (length > 0) {
			*buf = toupper(*buf);
			buf++;
			length--;
		}
		unlockBuffer(len);
	}
void GraphicsDeviceOGL::convertFrameBufferTo32bpp(u8* source, u32* pal)
{
	lockBuffer();
		const s32 curIndex = m_bufferIndex;
		u32 *dest = m_frameBuffer_32bpp[curIndex];

		u32 pixelCount = m_frameWidth*m_frameHeight;
		for (u32 p=0; p<pixelCount; p++)
		{
			*dest = pal[ *source ];
			dest++;
			source++;
		}
		m_writeBufferIndex = m_bufferIndex;
		m_bufferIndex = (m_bufferIndex+1)&1;
		m_writeFrame++;
	unlockBuffer();
}
// ***************************************************************************
void			CVegetableVBAllocator::clear()
{
	// clear list.
	_VertexFreeMemory.clear();
	_NumVerticesAllocated= 0;

	// must unlock for vbhard and vbsoft
	unlockBuffer();

	// delete the VB.
	deleteVertexBufferHard();
	// really delete the VB soft too
	_VBSoft.deleteAllVertices();

	// clear other states.
	_Driver= NULL;
	_VBHardOk= false;
}
Exemple #22
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Unlock profile data.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	September 20, 1993
 *------------------------------------------------------------------*/
void SpProfileUnlock (SpProfile_t Profile)
{

#if defined(KPMAC)

	SpProfileData_t	FAR *ProfileData;

	if (NULL == Profile)
		return;

	ProfileData = *((SpProfileData_t FAR **) Profile);
	ProfileData->LockCount--;
		
	/* lockCount == 0 means that we need to fully unlock the handle */
	if(ProfileData->LockCount == 0)
#endif
		unlockBuffer ((KcmHandle) Profile);

}
Exemple #23
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 * This function inverts the output tables of a PT
 *
 * AUTHOR
 * PGT
 *
 * DATE CREATED
 * May 11, 1994
 *--------------------------------------------------------------------*/
static PTErr_t
	InvertOutputTables (	PTRefNum_t	refNum,
							KpInt32_t	numOutChan)
{
KpInt32_t	i, k;
PTErr_t		cpStatus;
KcmHandle	refTblHandle;
KcmHandle	tblList[FUT_NOCHAN];
mf2_tbldat_p	refTbl;
KpInt32_t	numTbls, refTblEntries, dummy = 0;

	/* Get each table, invert if not already inverted */
	cpStatus = KCP_SUCCESS;
	numTbls = 0;
	for (i = 0; (i < numOutChan) && (cpStatus == KCP_SUCCESS); ++i) {
		cpStatus = getRefTbl (FUT_OMAGIC, refNum, dummy, i, &refTblHandle, &refTblEntries);
		if (cpStatus == KCP_NO_OUTTABLE) {
			cpStatus = KCP_SUCCESS;
		}
		else {
			if ((cpStatus == KCP_SUCCESS) && (UniqueTable (refTblHandle, tblList, numTbls))) {
				refTbl = lockBuffer (refTblHandle);
				if (refTbl != NULL) {
					tblList [numTbls++] = refTblHandle;	/* save address to avoid multiple inversion */

					for (k = 0; k < refTblEntries; ++k ) {		/* invert the table */
						refTbl[k] = (mf2_tbldat_t)(MF2_TBL_MAXVAL - refTbl[k]);	/* by negating the contents of each entry */
					}

					unlockBuffer (refTblHandle);
				}
				else {
					cpStatus = KCP_MEM_LOCK_ERR;
				}
			}
		}
	}

	return cpStatus;
}
Exemple #24
0
/*--------------------------------------------------------------------
 * DESCRIPTION	(Private -- phase out 5/4/95)
 *	Set the name of the file to associate with the profile.
 *	If the Name is NULL no file will be associated with the profile.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	Octorber 22, 1993
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileSetFileName (
    SpProfile_t		Profile,
    char			FAR *FileName)
{
    char			FAR *fileName;
    SpProfileData_t	FAR *ProfileData;

    /* convert profile handle to data pointer */
    ProfileData = SpProfileLock (Profile);
    if (NULL == ProfileData)
        return SpStatBadProfile;

    /* Free current FileName if one is there */
    if (ProfileData->FileName != NULL)
        freeBuffer(ProfileData->FileName);

    /* create the FileName handle */
    ProfileData->FileName = allocBufferHandle (strlen (FileName) + 1);
    if (ProfileData->FileName == NULL)
        return (SpStatMemory);

    /* lock FileName handle and return ptr */
    fileName = (char *) lockBuffer (ProfileData->FileName);
    if (fileName == NULL)
        return (SpStatMemory);

    /* copy text data into the newly allocated space */
    strcpy (fileName, FileName);

#if defined (KPMAC)
    SpProfileClearProps(&(ProfileData->Props));
#endif

    /* unlock handles */
    unlockBuffer (ProfileData->FileName);
    SpProfileUnlock (Profile);
    return SpStatSuccess;
}
Exemple #25
0
bool String8::removeAll(const char* other) {
    ssize_t index = find(other);
    if (index < 0) return false;

    char* buf = lockBuffer(size());
    if (!buf) return false; // out of memory

    size_t skip = strlen(other);
    size_t len = size();
    size_t tail = index;
    while (size_t(index) < len) {
        ssize_t next = find(other, index + skip);
        if (next < 0) {
            next = len;
        }

        memmove(buf + tail, buf + index + skip, next - index - skip);
        tail += next - index - skip;
        index = next;
    }
    unlockBuffer(tail);
    return true;
}
Exemple #26
0
	String8& String8::appendPath(const char* name)
	{
		// TODO: The test below will fail for Win32 paths. Fix later or ignore.
		if (name[0] != OS_PATH_SEPARATOR) {
			if (*name == '\0') {
				// nothing to do
				return *this;
			}

			size_t len = length();
			if (len == 0) {
				// no existing filename, just use the new one
				setPathName(name);
				return *this;
			}

			// make room for oldPath + '/' + newPath
			int newlen = strlen(name);

			char* buf = lockBuffer(len + 1 + newlen);

			// insert a '/' if needed
			if (buf[len - 1] != OS_PATH_SEPARATOR)
				buf[len++] = OS_PATH_SEPARATOR;

			memcpy(buf + len, name, newlen + 1);
			len += newlen;

			unlockBuffer(len);

			return *this;
		}
		else {
			setPathName(name);
			return *this;
		}
	}
Exemple #27
0
	void String8::unlockBuffer()
	{
		unlockBuffer(strlen(mString));
	}
Exemple #28
0
/* verify that two header info blocks are the same
 */
PTErr_t
	TpCompareHdr (	KpHandle_t	PTHdr1,
					KpHandle_t	PTHdr2)
{
PTErr_t errnum = KCP_SUCCESS;
KpInt32_t i1, i2;
chan_hdr_p chanf, chani;
fut_hdr_p futHdr1, futHdr2;

	if (PTHdr1 == PTHdr2) {
		return (KCP_SUCCESS);
	}

	futHdr1 = (fut_hdr_p)lockBuffer (PTHdr1);	/* get header pointer 1 */
	if (futHdr1 == NULL) {
		errnum = KCP_MEM_LOCK_ERR;
		goto GetOut;
	}

	futHdr2 = (fut_hdr_p)lockBuffer (PTHdr2);	/* get header pointer 2 */
	if (futHdr2 == NULL) {
		errnum = KCP_MEM_LOCK_ERR;
		goto GetOut;
	}

	if (	(futHdr1->magic != futHdr2->magic)
		||	(futHdr1->version != futHdr2->version)
	   	||	(futHdr1->order != futHdr2->order)) {
		errnum = KCP_INCON_PT;						/* no match */
		goto GetOut;
	}

	switch (futHdr1->magic) {
	case FUT_CIGAM: /* fut with bytes reversed */
	case FUT_MAGIC: /* fut with bytes in correct order */

		for (i1 = 0; i1 < FUT_NCHAN; i1++) {
			if (futHdr1->icode[i1] != futHdr2->icode[i1]) {
				errnum = KCP_INCON_PT;					/* no match */
				goto GetOut;
			}
		}

		for (i1=0, chanf=futHdr1->chan, chani=futHdr2->chan; i1<FUT_NCHAN; ++i1, chanf++, chani++) {
			if (chanf->gcode != chani->gcode) {
				errnum = KCP_INCON_PT;					/* no match */
				goto GetOut;
			}

			if (chanf->gcode != 0) {		/* if the channel is defined */
				for (i2 = 0; i2 < FUT_NCHAN; i2++) {
					if (chanf->icode[i2] != chani->icode[i2]) {
						errnum = KCP_INCON_PT;			/* no match */
						goto GetOut;
					}

				/* if this input is defined */
					if (chanf->icode[i2] != FUTIO_NULL) {
						if (chanf->size[i2] != chani->size[i2]) {
							errnum = KCP_INCON_PT;		/* no match */
							goto GetOut;
						}
					}
				}

				if (chanf->ocode != chani->ocode) {
					errnum = KCP_INCON_PT;				/* no match */
					goto GetOut;
				}
			}
		}

		if (futHdr1->more != futHdr2->more) {
			errnum = KCP_INCON_PT;						/* no match */
			goto GetOut;
		}
		break;

	case PTTYPE_MFT1:	/* 8 bit matrix fut */
	case PTTYPE_MFT2:	/* 16 bit matrix fut */
	case PTTYPE_MA2B:
	case PTTYPE_MB2A:
		for (i1 = 0; i1 < 2; i1++) {
			if (futHdr1->icode[i1] != futHdr2->icode[i1]) {
				errnum = KCP_INCON_PT;						/* no match */
				goto GetOut;
			}
		}
		break;
		
	default:
		return (KCP_INVAL_PT_BLOCK);		/* unknown type */
	}


GetOut:
	if ( ! unlockBuffer (PTHdr1)) {
		errnum = KCP_MEM_UNLOCK_ERR;
	}
	if ( ! unlockBuffer (PTHdr2)) {
		errnum = KCP_MEM_UNLOCK_ERR;
	}

	return errnum;
}
Exemple #29
0
/* TpReadData reads a fut from a memory block and returns a handle to a newly allocated fut
 */
PTErr_t
	TpReadData(	KpFd_p			fd,
				PTType_t		format,
				PTRefNum_t		PTRefNum,
				KpHandle_t		PTHdr,
				KpHandle_t FAR*	PTData)
{
PTErr_t			errnum;
fut_p			fut = NULL, theFutFromMatrix = NULL, newFut = NULL, lab2xyzFut = NULL, finalFut = NULL;
fut_hdr_p		futHdr;
Fixed_t			matrix[MF_MATRIX_DIM * MF_MATRIX_DIM + MF_MATRIX_DIM];
KpInt32_t		ret, iomask;
KpChar_t		ENUM_String[20];
KpInt32_t		inCS, i, i1;
ResponseRecord_t	inRedTRC, inGreenTRC, inBlueTRC;
ResponseRecord_t	outRedTRC, outGreenTRC, outBlueTRC;
PTRefNum_t		matrixPTRefNum;
PTDataClass_t 	iClass, oClass;

	futHdr = (fut_hdr_p) lockBuffer (PTHdr);	/* get buffer pointer */
	if (futHdr == NULL) {
		errnum = KCP_MEM_LOCK_ERR;
		goto GetOut;
	}

	futHdr->profileType = getIntAttrDef (PTRefNum, KCM_ICC_PROFILE_TYPE);
	futHdr->spaceIn = getIntAttrDef (PTRefNum, KCM_SPACE_IN);
	futHdr->spaceOut = getIntAttrDef (PTRefNum, KCM_SPACE_OUT);
	futHdr->iDataClass = getDataClass (futHdr->spaceIn);
	futHdr->oDataClass = getDataClass (futHdr->spaceOut);

	switch (format) {
	case FUT_CIGAM: /* fut with bytes reversed */
	case FUT_MAGIC: /* fut with bytes in correct order */
		if ((fut = fut_alloc_fut ()) == NULL) {	/* allocate a new fut structure */
			errnum = KCP_NO_ACTIVATE_MEM;
		}
		else {
			if (fut_read_tbls (fd, fut, futHdr) != 1) {	/* read fut tables */
				errnum = KCP_PT_DATA_READ_ERR;
			}
			else {
				if (fut_io_decode (fut, futHdr) == 0) {
					errnum = KCP_PTERR_0;
				}
				else {
					errnum = KCP_SUCCESS;
				}
			}
		}
		break;

	case PTTYPE_MFT1:
	case PTTYPE_MFT2:
		fut = fut_readMFutTbls (fd, futHdr, matrix);	/* read matrix fut tables */
		if (fut == NULL) {
			errnum = KCP_NO_ACTIVATE_MEM;
		}
		else {
			inCS = getIntAttrDef (PTRefNum, KCM_SPACE_IN);

			if ((inCS == KCM_CIE_XYZ) && (isIdentityMatrix (matrix, MF_MATRIX_DIM) != 1)) {
				ret = makeOutputMatrixXform ((Fixed_p)&matrix, 8, &theFutFromMatrix);
				if (ret != 1) {
					errnum = KCP_INCON_PT;
					goto GetOut;
				}
				else {
					iomask = FUT_PASS(FUT_XYZ);		/* get the Lab to XYZ fut */
					lab2xyzFut = get_lab2xyz (KCP_GRID_DIM_SIXTEEN);

					newFut = fut_comp (theFutFromMatrix, lab2xyzFut, iomask);			

					if (newFut != NULL) {
						finalFut = fut_comp (fut, newFut, iomask);
					}			

					fut_free (theFutFromMatrix);	/* free intermediate futs */
					fut_free (lab2xyzFut);
					fut_free (fut);
					fut_free (newFut);

					fut = finalFut;

					/* set the input color space attribute to Lab */
					KpItoa (KCM_CIE_LAB, ENUM_String);
					errnum = PTSetAttribute (PTRefNum, KCM_SPACE_IN, ENUM_String);
					if (errnum != KCP_SUCCESS) {
						goto GetOut;
					}

					/* set the input composition attribute to Lab */
					errnum = PTSetAttribute (PTRefNum, KCM_IN_CHAIN_CLASS_2, "6");
					if (errnum != KCP_SUCCESS) {
						goto GetOut;
					}
				}
			}

			if ((fut == NULL) || !fut_io_encode (fut, futHdr)) {	/* make the info header */
				errnum = KCP_INCON_PT;
				goto GetOut;
			}

			errnum = KCP_SUCCESS;
		}
		break;

	case PTTYPE_MA2B:
	case PTTYPE_MB2A:
	
		matrix[0] = matrix[4] = matrix[8] = KpF15d16FromDouble(1.0);
		matrix[1] = matrix[2] = matrix[3] = 
		matrix[5] = matrix[6] = matrix[7] = 
		matrix[9] = matrix[10] = matrix[11] = KpF15d16FromDouble(0.0);
		
		fut = fut_readMabFutTbls (fd, futHdr, matrix);	/* read matrix fut tables */
		if (fut == NULL) {
			errnum = KCP_NO_ACTIVATE_MEM;
		}
		else {
			if (fut->lutConfig & HAS_MATRIX_DATA) {
				i = MF_MATRIX_DIM * MF_MATRIX_DIM + MF_MATRIX_DIM;
				for (i1 = 0; i1 < i; i1++)
				{
					fut->matrix[i1] = matrix[i1];
				}
				switch (fut->lutConfig) {
				case MAB_M_MATRIX_B_COMBO:
				case MBA_B_MATRIX_M_COMBO:
					inRedTRC.CurveCount = fut->mabInTblEntries[0];
					inGreenTRC.CurveCount = fut->mabInTblEntries[1];
					inBlueTRC.CurveCount = fut->mabInTblEntries[2];
					inRedTRC.CurveData = fut->mabInRefTbl[0];
					inGreenTRC.CurveData = fut->mabInRefTbl[1];
					inBlueTRC.CurveData = fut->mabInRefTbl[2];
					outRedTRC.CurveCount = fut->mabOutTblEntries[0];
					outGreenTRC.CurveCount = fut->mabOutTblEntries[1];
					outBlueTRC.CurveCount = fut->mabOutTblEntries[2];
					outRedTRC.CurveData = fut->mabOutRefTbl[0];
					outGreenTRC.CurveData = fut->mabOutRefTbl[1];
					outBlueTRC.CurveData = fut->mabOutRefTbl[2];
					iClass = getDataClass(futHdr->spaceIn);
					oClass = getDataClass(futHdr->spaceOut);
					ret = makeFutFromMatrix ((Fixed_p)&matrix, &inRedTRC, &inGreenTRC, &inBlueTRC, 
												&outRedTRC, &outGreenTRC, &outBlueTRC, MATRIX_GRID_SIZE, iClass, oClass, 
												(fut_p *)&theFutFromMatrix);
					break;

				case MBA_B_MATRIX_M_CLUT_A_COMBO:
					inRedTRC.CurveCount = fut->mabInTblEntries[0];
					inGreenTRC.CurveCount = fut->mabInTblEntries[1];
					inBlueTRC.CurveCount = fut->mabInTblEntries[2];
					inRedTRC.CurveData = fut->mabInRefTbl[0];
					inGreenTRC.CurveData = fut->mabInRefTbl[1];
					inBlueTRC.CurveData = fut->mabInRefTbl[2];
					iClass = getDataClass(futHdr->spaceIn);
					oClass = KCP_UNKNOWN;
					ret = makeFutFromMatrix ((Fixed_p)&matrix, &inRedTRC, &inGreenTRC, &inBlueTRC, 
												NULL, NULL, NULL, MATRIX_GRID_SIZE, iClass, oClass, (fut_p *)&theFutFromMatrix);
					break;

				case MAB_A_CLUT_M_MATRIX_B_COMBO:
					outRedTRC.CurveCount = fut->mabOutTblEntries[0];
					outGreenTRC.CurveCount = fut->mabOutTblEntries[1];
					outBlueTRC.CurveCount = fut->mabOutTblEntries[2];
					outRedTRC.CurveData = fut->mabOutRefTbl[0];
					outGreenTRC.CurveData = fut->mabOutRefTbl[1];
					outBlueTRC.CurveData = fut->mabOutRefTbl[2];
					iClass = KCP_UNKNOWN;
					oClass = getDataClass(futHdr->spaceOut);
					ret = makeFutFromMatrix ((Fixed_p)&matrix, NULL, NULL, NULL, &outRedTRC, &outGreenTRC,
												&outBlueTRC, MATRIX_GRID_SIZE, iClass, oClass, (fut_p *)&theFutFromMatrix);
					break;

				default:
					break;
				}
				if (NULL != theFutFromMatrix)
				{
					/* Create a PT from the fut */
					errnum = fut2PT (&theFutFromMatrix, KCM_UNKNOWN, KCM_UNKNOWN, PTTYPE_CALCULATED, &matrixPTRefNum);
					if (errnum != KCP_SUCCESS) {
						goto GetOut;
					}
					errnum = setMatrixPTRefNum (PTRefNum, matrixPTRefNum, fut->lutConfig);
					if (errnum != KCP_SUCCESS) {
						goto GetOut;
					}
				}
				if (ret != 1) {
					errnum = KCP_INCON_PT;
					goto GetOut;
				}
			}

			if ((fut == NULL) || !fut_io_encode (fut, futHdr)) {	/* make the info header */
				errnum = KCP_INCON_PT;
				goto GetOut;
			}

			errnum = KCP_SUCCESS;
		}
		break;

	default:
		break;
	}


GetOut:
	if ((errnum != KCP_SUCCESS) || (fut == NULL)) {
		fut_free (fut);
	}
	else {		/* return handle to fut to caller */

	/* make sure the futs are in the reference state */
		if (fut_to_mft (fut) == 1) {
			*PTData = (KpHandle_t)fut_unlock_fut (fut);
		}
	}

	if ( ! unlockBuffer (PTHdr)) {
		errnum = KCP_MEM_UNLOCK_ERR;
	}

	return errnum;
}
Exemple #30
0
KpInt32_t unlockSysBuffer (KpHandle_t handle)
{
        return (unlockBuffer (handle));
}