示例#1
0
// ---------------------------------------
// Load Image File function w. filters.
// ---------------------------------------
BOOL LoadImageFile(LPRDATA rdPtr, LPSURFACE psf, LPSTR pFileName, DWORD dwFlags) 
{ 
	BOOL    bOK = FALSE; 
	LPRH    rhPtr = rdPtr->rHo.hoAdRunHeader; 
	HANDLE    hf = INVALID_HANDLE_VALUE; 

	do { 
		if ( pFileName == NULL || *pFileName == 0 ) 
			break; 

		// Copy filename to temporary string 
		char fname[MAX_PATH]; 
		strcpy(fname, pFileName); 

		// Open file 
		// 
		// mvOpenHFile opens the file directly from the CCN/EXE file ifthe file has been included in the embedded binary files of the application. 
		// If the file is not embedded, mvOpenHFile opens it from its current location (and downloads it first in Vitalize mode). 
		// 
		DWORD dwSize;                                    // file size 
		hf = rhPtr->rh4.rh4Mv->mvOpenHFile(fname, &dwSize, 0); 
		if ( hf == INVALID_HANDLE_VALUE ) 
			break; 

		// Create CInputFile 
		DWORD dwOff = File_GetPosition((HFILE)hf);        // position of embedded file in CCN/EXE file (0 if not embedded) 
		CInputBufFile bf; 
		if ( bf.Create((HFILE)hf, dwOff, dwSize) != 0 ) 
			break; 

		// Load picture 
		if ( ImportImageFromInputFile(rhPtr->rh4.rh4Mv->mvImgFilterMgr, &bf, psf, NULL, dwFlags) ) 
			bOK = TRUE; 

	} while(FALSE); 

	if ( hf != INVALID_HANDLE_VALUE ) 
		rhPtr->rh4.rh4Mv->mvCloseHFile(hf); 

	return bOK; 
}
示例#2
0
void LoadImageFile(LPRDATA rdPtr, LPSTR pFileName)
{
	LPRH	rhPtr = rdPtr->rHo.hoAdRunHeader;
	HANDLE	hf = INVALID_HANDLE_VALUE;

	do {	
		if ( pFileName == NULL || *pFileName == 0 )
			break;

		// Copy filename to temp buffer
		char fname[MAX_PATH];
		strcpy(fname, pFileName);

		// Get surface prototype
		LPSURFACE wSurf = WinGetSurface((int)rhPtr->rhIdEditWin);
		LPSURFACE proto;
		GetSurfacePrototype(&proto, (wSurf != NULL) ? wSurf->GetDepth() : 24, ST_MEMORYWITHDC, SD_DIB);
		if ( proto == NULL )
			break;

		// Ask MMF2 to open the file (opens external file and embedded files, and downloads files in Vitalize mode)
		DWORD dwSize;
		hf = rhPtr->rh4.rh4Mv->mvOpenHFile(fname, &dwSize, 0);
		if ( hf == INVALID_HANDLE_VALUE )
			break;

		// Create CInpuBufFile object associated with the file handle
		DWORD dwOff = File_GetPosition((HFILE)hf);
		CInputBufFile bf;
		if ( bf.Create((HFILE)hf, dwOff, dwSize) != 0 )
			break;

		// Create surface
		cSurface* psf = NewSurface();
		if ( psf == NULL )
			break;
		psf->Create(4, 4, proto);
		psf->Fill(RGB(0,0,0));
		if ( psf->GetDepth() == 8 )
			psf->SetPalette (*wSurf);

		// Load picture
		CImageFilterMgr* pImgMgr = rhPtr->rh4.rh4Mv->mvImgFilterMgr;
		if ( ImportImageFromInputFile(pImgMgr, &bf, psf, NULL, IMPORT_IMAGE_USESURFACEDEPTH | IMPORT_IMAGE_USESURFACEPALETTE) )
		{
			// Copy filename if file successfully loaded
			strcpy(rdPtr->sFilename, fname);
			rdPtr->nWidth = rdPtr->rHo.hoImgWidth = psf->GetWidth();
			rdPtr->nHeight = rdPtr->rHo.hoImgHeight = psf->GetHeight();

			// Replace picture surface
			if ( rdPtr->pSf != NULL )
				DeleteSurface(rdPtr->pSf);
			rdPtr->pSf = psf;

			// Free collision mask
			FreeColMask(rdPtr);

			// Set transparent color
			if ( psf->GetTransparentColor() == RGB(0,0,0) )
			{
				COLORREF trspColor = rdPtr->dwTranspColor;
				if ( (rdPtr->dwOptions & SPICTFLAGS_TRANSP_FIRSTPIXEL) != 0 )
					psf->GetPixel(0,0,trspColor);
				psf->SetTransparentColor(trspColor);
			}
		}
		else
			DeleteSurface(psf);

	} while(FALSE);

	// Close picture file (opened with mvOpenHFile)
	if ( hf != INVALID_HANDLE_VALUE )
		rhPtr->rh4.rh4Mv->mvCloseHFile(hf);
}