Bool CTexture2D::SetRawDataFromFile( const CFilePath& path )
{
    if( path.Exist() == FALSE )
        return FALSE;

    CoreManager.GetMemoryManager().GetStackHeap().PushMarker();
    {
        CImageFile* imageFile = NULL;
        CDDSFile ddsFile;
        CTGAFile tgaFile( &CoreManager.GetMemoryManager().GetStackHeap() );

        UInt32 offset = 0;
        Byte* destinationdata;
        UInt8 index;
        Char ext[6];

        path.GetExtension( ext, 6 );
        StringToLower( ext, ext, 6 );

        if( StringCompare( ext, "tga" ) == 0 )
            imageFile = &tgaFile;
        else if( StringCompare( ext, "dds" ) == 0 )
            imageFile = &ddsFile;

        if( imageFile && !imageFile->Load( path ) )
        {
            CoreManager.GetMemoryManager().GetStackHeap().PopMarker();
            return FALSE;
        }

        DebugAssert( imageFile->GetIsStandardTexture() );

        SetTextureInfo( imageFile->GetTextureInfo() );

        m_RawData.SetItemCount( GetTextureInfo().GetTextureByteCount() );
        destinationdata = m_RawData.GetBuffer();

        for( index = 0 ; index < GetTextureInfo().MipMapCount; index++)
        {
            UInt32 mipMapSize;
            const Byte* srcData = imageFile->GetSurfaceData( 0, index, mipMapSize );

            MemoryCopy( srcData, destinationdata + offset, mipMapSize );
            offset += mipMapSize;
        }
    }

    CoreManager.GetMemoryManager().GetStackHeap().PopMarker();

    return TRUE;
}
Exemple #2
0
HBITMAP CImageFile::LoadBitmap(HINSTANCE hInstance, UINT nResourceID, LPCTSTR pszType)
{
	HMODULE hModule = (HMODULE)hInstance;
	HRSRC hRes = FindResource( hModule, MAKEINTRESOURCE( nResourceID ), pszType );
	
	if ( hRes == NULL ) return NULL;
	
	DWORD nLength		= SizeofResource( hModule, hRes );
	HGLOBAL hMemory		= ::LoadResource( hModule, hRes );
	LPCVOID pBuffer		= (LPCVOID)LockResource( hMemory );

	CImageFile pImageFile;
	return pImageFile.LoadFromMemory( pBuffer, nLength );
}
void CLibraryMetaPanel::OnRun()
{
	m_pSection.Lock();

	while ( IsThreadEnabled() )
	{	
		CString strPath = m_sPath;

		if ( strPath.IsEmpty() )
			break;

		m_pSection.Unlock();

		CImageFile pFile;
		BOOL bSuccess = CThumbCache::Cache( strPath, &pFile );

		m_pSection.Lock();

		// If nothing changes
		if ( m_sPath == strPath )
		{
			if ( bSuccess )
			{
				if ( m_bmThumb.m_hObject )
					m_bmThumb.DeleteObject();

				m_bmThumb.Attach( pFile.CreateBitmap() );
			}

			Invalidate();

			break;
		}
	}

	m_pSection.Unlock();
}
void CLibraryTipCtrl::OnRun()
{
	while ( IsThreadEnabled() )
	{
		Doze( 1000 );

		if ( ! IsThreadEnabled() )
			break;

		m_pSection.Lock();
		CString strPath = m_sPath;
		m_pSection.Unlock();

		if ( strPath.IsEmpty() )	// ToDo: Make preview requests by hash?
			continue;

		CImageFile pFile;
		BOOL bSuccess = CThumbCache::Cache( strPath, &pFile );

		m_pSection.Lock();

		if ( m_bmThumb.m_hObject ) m_bmThumb.DeleteObject();

		if ( m_sPath == strPath )
		{
			m_sPath.Empty();

			if ( bSuccess )
			{
				m_bmThumb.Attach( pFile.CreateBitmap() );
				Invalidate();
			}
		}

		m_pSection.Unlock();
	}
}
Exemple #5
0
void CDownloadTask::RunPreviewRequest()
{
	m_bSuccess = m_pRequest->Execute( false );	// Without threading

	if ( ! IsThreadEnabled() || m_pDownload->m_sPath.IsEmpty() ) return;

	// Save downloaded preview as png-file
	const CString strPath = m_pDownload->m_sPath + L".png";
	CImageFile pImage;
	CBuffer* pBuffer = IsPreviewAnswerValid( m_pDownload->m_oSHA1 );
	if ( pBuffer && pBuffer->m_pBuffer && pBuffer->m_nLength &&
		 pImage.LoadFromMemory( L".jpg", pBuffer->m_pBuffer, pBuffer->m_nLength, FALSE, TRUE ) &&
		 pImage.SaveToFile( (LPCTSTR)strPath, 100 ) )
	{
		// Make it hidden, so the files won't be shared
		SetFileAttributes( (LPCTSTR)strPath, FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM );
	}
	else
	{
		// Failed
		m_pDownload->m_bWaitingPreview = FALSE;
		theApp.Message( MSG_ERROR, IDS_SEARCH_DETAILS_PREVIEW_FAILED, (LPCTSTR)GetRequest() );
	}
}
Exemple #6
0
BOOL CEmoticons::LoadXML(LPCTSTR pszFile)
{
    CString strPath, strValue;

    CXMLElement* pXML = CXMLElement::FromFile( pszFile, TRUE );
    if ( pXML == NULL ) return FALSE;

    strPath = pszFile;
    int nSlash = strPath.ReverseFind( '\\' );
    if ( nSlash >= 0 ) strPath = strPath.Left( nSlash + 1 );

    CXMLElement* pBitmap = pXML->GetElementByName( _T("bitmap") );

    if ( pBitmap == NULL )
    {
        delete pXML;
        return FALSE;
    }

    strValue = pBitmap->GetAttributeValue( _T("file") );

    nSlash = strValue.ReverseFind( '/' );
    if ( nSlash >= 0 ) strValue = strValue.Mid( nSlash + 1 );
    strValue = strPath + strValue;

    CImageFile pImage;

    if ( ! pImage.LoadFromFile( strValue ) ||
            ! pImage.EnsureRGB( GetSysColor( COLOR_WINDOW ) ) ||
            ! pImage.SwapRGB() )
    {
        delete pXML;
        return FALSE;
    }

    COLORREF crBack = RGB( pImage.m_pImage[2], pImage.m_pImage[1], pImage.m_pImage[0] );

    for ( POSITION pos = pXML->GetElementIterator() ; pos ; )
    {
        CXMLElement* pEmoticon = pXML->GetNextElement( pos );
        if ( ! pEmoticon->IsNamed( _T("emoticon") ) ) continue;

        CXMLElement* pSource = pEmoticon->GetElementByName( _T("source") );
        CString strText = pEmoticon->GetAttributeValue( _T("text") );
        CRect rc( 0, 0, 0, 0 );

        strValue = pSource->GetAttributeValue( _T("left"), _T("0") );
        _stscanf( strValue, _T("%i"), &rc.left );
        strValue = pSource->GetAttributeValue( _T("top"), _T("0") );
        _stscanf( strValue, _T("%i"), &rc.top );
        strValue = pSource->GetAttributeValue( _T("right"), _T("0") );
        _stscanf( strValue, _T("%i"), &rc.right );
        strValue = pSource->GetAttributeValue( _T("bottom"), _T("0") );
        _stscanf( strValue, _T("%i"), &rc.bottom );

        BOOL bButton = pEmoticon->GetAttributeValue( _T("button") ).CompareNoCase( _T("yes") ) == 0;

        AddEmoticon( strText, &pImage, &rc, crBack, bButton );
    }

    delete pXML;

    return TRUE;
}