Ejemplo n.º 1
0
////////////////////////////////////////////////////////////////
// CStream::ReadString
//
/////////////////////////////////////////////////////////////////
HRESULT CStream::ReadString(REFIID riid, DBLENGTH ulOffset, DBLENGTH cBytes, DBLENGTH ulMaxSize, WCHAR* pwszBuffer, DBLENGTH* pcbRead)
{
	ASSERT(pwszBuffer);
	HRESULT hr = S_OK;
	pwszBuffer[0] = wEOL;
	
	WCHAR	pBuffer[MAX_COL_SIZE+1] = {0};
	DWORD	dwConvFlags = GetOptions()->m_dwConvFlags; 

	DBLENGTH cbRead = 0;
	cBytes = min(min(sizeof(pBuffer), cBytes), ulMaxSize*sizeof(WCHAR));
	
	//Delegate
	TESTC(hr = ReadBytes(riid, ulOffset, cBytes, ulMaxSize*sizeof(WCHAR), pBuffer, &cbRead));

	//What type of data are we reading
	switch(m_wType)
	{
		case DBTYPE_WSTR:
		case DBTYPE_STR:
			//Add a NULL terminator on the end of the data before conversion
			//since the spec indicates the stream is not NULL terminated...
			//NOTE: We made sure we had a full extra WCHAR in the buffer ahead of time
			memset((BYTE*)pBuffer + min(cBytes, cbRead), 0, sizeof(WCHAR));
			cbRead += (m_wType == DBTYPE_WSTR) ? sizeof(WCHAR) : sizeof(CHAR);
			break;
	};

	//Now that we have read the data, coerce it into a string for display purposes...
	XTESTC_(hr = DataConvert
		(
			DBSTATUS_S_OK,
			cbRead,
			sizeof(pBuffer),	
			(m_wType == DBTYPE_WSTR || m_wType == DBTYPE_STR) ? m_wType : DBTYPE_BYTES,
			pBuffer,
			0,
			0,
			
			DBTYPE_WSTR,
			NULL,
			NULL,
			pwszBuffer,
			ulMaxSize*sizeof(WCHAR),
			dwConvFlags
		),S_OK);

CLEANUP:
	if(pcbRead)
		*pcbRead = cbRead;
	return hr;
}
Ejemplo n.º 2
0
////////////////////////////////////////////////////////////////
// CStream::WriteString
//
/////////////////////////////////////////////////////////////////
HRESULT CStream::WriteString(REFIID riid, DBLENGTH ulOffset, DBLENGTH cBytes, WCHAR* pwszBuffer, DBLENGTH* pcbWritten)
{
	HRESULT hr = S_OK;
	WCHAR	pBuffer[MAX_COL_SIZE] = {0};
	DWORD	dwConvFlags = GetOptions()->m_dwConvFlags; 

	DBLENGTH cbWritten = 0;
	cBytes = min(sizeof(pBuffer), cBytes);

	//First Convert the user entered data into the backend format...
	//So the stream is a native stream of bytes to set into the backend...
	XTESTC_(hr = DataConvert
		(
			DBSTATUS_S_OK, 
			cBytes, 
			cBytes + sizeof(WCHAR),
			DBTYPE_WSTR,
			pwszBuffer,
			0,	//Precision
			0,	//Scale
			
			(m_wType == DBTYPE_IUNKNOWN || m_wType == (DBTYPE_BYREF|DBTYPE_IUNKNOWN))
				? DBTYPE_BYTES : m_wType,
			
			NULL,		//&dbDstStatus
			&cBytes,	//&cbDstLength
			pBuffer,
			sizeof(pBuffer),
			dwConvFlags
		),S_OK);


	//Delegate
	TESTC(hr = WriteBytes(riid, ulOffset, cBytes, pBuffer, &cbWritten));

CLEANUP:
	if(pcbWritten)
		*pcbWritten = cbWritten;
	return hr;
}
Ejemplo n.º 3
0
bool CPNGFile::CreatePNGFromPNG(char *szSrcFile, char *szDstFile, int nDstBitDepth)
{
	if ( !SetPNG( szSrcFile, nDstBitDepth ))
		return false;

	int bufLen = 5*m_idat.GetChunkDataLength();
	BYTE * buf = new BYTE[bufLen]; // assuming 500 compress rate

	if( buf == NULL )
		return false;

	BYTE *bufOrg = new BYTE[m_idat.GetChunkDataLength()];
	
	if( bufOrg == NULL )
		return false;
	
	m_idat.GetChunkData( bufOrg, m_idat.GetChunkDataLength() );
	int nRet = uncompress( buf, (unsigned long*)&bufLen, bufOrg, m_idat.GetChunkDataLength() );

	delete []bufOrg;

	DataConvert( &buf, bufLen, m_ihdr.GetWidth(), m_ihdr.GetColorDepth(), nDstBitDepth);

	m_ihdr.SetColorDepth(nDstBitDepth);

	unsigned long  nLen = (unsigned long)(bufLen * 1.2);

	bufOrg = new BYTE[nLen];
	
	if( bufOrg == NULL )
		return false;

	

	nRet = compress( bufOrg, &nLen, buf, bufLen );
	m_idat.SetChunkData( bufOrg, nLen );


	FILE *fp = fopen( szDstFile, "w+b" );
	if ( fp == NULL )
		return false;

	unsigned char szBuf[0x4000];

	fwrite( m_szHeader, 8, 1, fp );
	nLen=0x4000;
	nLen = m_ihdr.GetChunk( szBuf, nLen);
	fwrite( szBuf, nLen, 1, fp );
	nLen=0x4000;
	nLen = m_plte.GetChunk( szBuf, nLen);
	fwrite( szBuf, nLen, 1, fp );
	nLen=0x4000;
	nLen = m_trns.GetChunk( szBuf, nLen);
	fwrite( szBuf, nLen, 1, fp );
	nLen=0x4000;
	nLen = m_idat.GetChunk( szBuf, nLen);
	fwrite( szBuf, nLen, 1, fp );
	nLen=0x4000;
	nLen = m_iend.GetChunk( szBuf, nLen);
	fwrite( szBuf, nLen, 1, fp );

	fclose(fp);
	return true;
}