Exemple #1
0
//////////////////////////////////////////////////////////////
// Description   :  Check which file type specified and call
//                  appropriate loader.  return new surface.
//////////////////////////////////////////////////////////////
CDX_LPDIRECTDRAWSURFACE CDXImage::GetImage(CDX_LPDIRECTDRAW lpDD, const char *filename, BYTE memType, DWORD type)
{
    CDX_LPDIRECTDRAWSURFACE lpdds = NULL;
    LONG lSize;
    CDXFile fs;
    CHAR* lpCache;

    if (FAILED(fs.OpenRead(filename)))
        return NULL;

    // Get the file size.
    lSize = fs.FileSize();
    // Allocate memory to hold the data
    lpCache = new CHAR[lSize];

    if (lpCache == NULL) {
        fs.Close();
        return NULL;
    }

    if ((DWORD)lSize != fs.Read(lpCache, lSize)) {
        delete [] lpCache;
        fs.Close();
        return NULL;
    }

    // Close the file stream
    fs.Close();
    // Call GetImage for the appropriate image type
    lpdds = CreateDDSurface(lpDD, lSize, lpCache, memType, type);
    // Delete the cache
    delete [] lpCache;
    return lpdds;
}
Exemple #2
0
//////////////////////////////////////////////////////////////
// Description   :  Check which file type specified and call
//                  appropriate loader.  return new surface.
//////////////////////////////////////////////////////////////
CDX_LPDIRECTDRAWSURFACE CDXImage::GetImage(CDX_LPDIRECTDRAW lpDD, LONG lSize, CHAR* lpCache, BYTE memType, DWORD type)
{
    CDX_LPDIRECTDRAWSURFACE lpdds = NULL;
    // Call GetImage for the appropriate image type
    lpdds = CreateDDSurface(lpDD, lSize, lpCache, memType, type);
    return lpdds;
}
Exemple #3
0
//////////////////////////////////////////////////////////////
// Description   :  Check which file type specified and call
//                  appropriate loader.  return new surface.
//////////////////////////////////////////////////////////////
CDX_LPDIRECTDRAWSURFACE CDXImage::GetImage(CDX_LPDIRECTDRAW lpDD, LONG lSize, FILE* fh, BYTE memType, DWORD type)
{
    CDX_LPDIRECTDRAWSURFACE lpdds = NULL;
    CHAR* lpCache;
    int length, save;
    length = lSize;

    // If lSize equals zero get the size of the file.
    if (length == 0) {
        // Save the pointer location
        save = ftell(fh);

        if (ferror(fh))
            return NULL;

        // Seek to end of file
        fseek(fh, 0, SEEK_END);

        if (ferror(fh))
            return NULL;

        // Get the size of the file
        length = ftell(fh);

        if (ferror(fh))
            return NULL;

        // Seek back to save position
        fseek(fh, save, SEEK_SET);

        if (ferror(fh))
            return NULL;
    }

    // Cache the whole file in memory
    // Allocate memory to hold the data
    lpCache = new CHAR[length];

    if (lpCache == NULL)
        return NULL;

    // Read in the data
    fread(lpCache, 1, length, fh);

    if (ferror(fh)) {
        delete [] lpCache;
        return NULL;
    }

    // Call GetImage for the appropriate image type
    lpdds = CreateDDSurface(lpDD, length, lpCache, memType, type);
    // Delete the cache
    delete [] lpCache;
    return lpdds;
}
Exemple #4
0
//////////////////////////////////////////////////////////////
// Description   :  Check which file type specified and call
//                  appropriate loader.  return new surface.
//////////////////////////////////////////////////////////////
CDX_LPDIRECTDRAWSURFACE CDXImage::GetImage(CDX_LPDIRECTDRAW lpDD, LONG lSize, CDXFile* fsptr, BYTE memType, DWORD type)
{
    CDX_LPDIRECTDRAWSURFACE lpdds = NULL;
    CHAR* lpCache;
    int length, save;
    length = lSize;

    // If lSize equals zero get the size of the file.
    if (length == 0) {
        // Save the pointer location
        save = fsptr->Position();
        // Get the size of the file
        length = fsptr->FileSize();
        // Seek back to save position
        fsptr->Position(save, FILE_BEGIN);
    }

    // Cache the whole file in memory
    // Allocate memory to hold the data
    lpCache = new CHAR[length];

    if (lpCache == NULL)
        return NULL;

    // Read in the data
    if (fsptr->Read(lpCache, length) == 0) {
        delete [] lpCache;
        return NULL;
    }

    // Call GetImage for the appropriate image type
    lpdds = CreateDDSurface(lpDD, length, lpCache, memType, type);
    // Delete the cache
    delete [] lpCache;
    return lpdds;
}
Exemple #5
0
//+------------------------------------------------------------------------
//
//  Member:     COffScreenContext::GetDDSurface
//
//  Synopsis:   Create a suitable DD surface or get one from the cache.
//
//-------------------------------------------------------------------------
BOOL COffScreenContext::GetDDSurface(HPALETTE hpal)
{
	HRESULT hr;
	LOCK_SECTION(g_csOscCache);

	if(!g_OscCache._fInUse)
	{
		ClearDDBCache(); // don't allow both DD & DDB in the cache

		if(g_OscCache._pDDSurface != NULL)
		{
			Assert(g_OscCache._fUseDD);
			if(_widthActual>g_OscCache._size.cx
				|| _heightActual>g_OscCache._size.cy
				|| _cBitsPixel!=g_OscCache._cBitsPixel
				|| (_fUse3D&&!g_OscCache._fUse3D))
			{
				++g_OscCache._cMisses;
				ClearSurfaceCache();
			}
			else
			{
				++g_OscCache._cHits;
				g_OscCache._fInUse = TRUE;
				_pDDSurface = g_OscCache._pDDSurface;
				_pDDSurface->AddRef();
				_hdcMem = g_OscCache._hdcMem;
				_widthActual = g_OscCache._size.cx;
				_heightActual = g_OscCache._size.cy;
			}
		}
		if(g_OscCache._pDDSurface == NULL)
		{
			// use max area allowed for the cache, so we get max reuse potential
			// favor width over height for those wide text runs
			// also adjust the max size in a growing fashion based on former allocations
			g_OscCache._size.cx = max(g_OscCache._size.cx, max(min(g_OscCache._areaTgt/_heightActual, g_OscCache._sizeTgt.cx), _widthActual));
			g_OscCache._size.cy = max(g_OscCache._size.cy , max(g_OscCache._areaTgt/g_OscCache._size.cx, _heightActual));
			if(!CreateDDSurface(g_OscCache._size.cx, g_OscCache._size.cy, hpal))
			{
				return FALSE;
			}
			Trace0("surface cache created\n");
			g_OscCache._fInUse = TRUE;
			g_OscCache._fUseDD = TRUE;
			g_OscCache._fUse3D = _fUse3D;
			g_OscCache._pDDSurface = _pDDSurface;
			g_OscCache._pDDSurface->AddRef(); // addref the global surface
			g_OscCache._cBitsPixel = _cBitsPixel;
			g_OscCache._hdcMem = _hdcMem;
			g_OscCache._hpal = hpal;
			_widthActual = g_OscCache._size.cx;
			_heightActual = g_OscCache._size.cy;
		}
	}
	else
	{
		Trace0("surface cache in use\n");
	}

	if(_pDDSurface == NULL)
	{
		if(!CreateDDSurface(_widthActual, _heightActual, hpal))
		{
			return FALSE;
		}
	}

	// reset the color table when using cache
	if(_cBitsPixel==8 && _pDDSurface==g_OscCache._pDDSurface
		&& (hpal!=g_OscCache._hpal || hpal!=g_hpalHalftone))
	{
		IDirectDrawPalette* pDDPal;
		PALETTEENTRY pal256[256];
		long cEntries;

		cEntries = GetPaletteEntries(hpal, 0, 256, pal256);

		// get the DD palette and set entries
		hr = _pDDSurface->GetPalette(&pDDPal);
		if(SUCCEEDED(hr))
		{
			hr = pDDPal->SetEntries(0, 0, cEntries, pal256);
			pDDPal->Release();
			if(SUCCEEDED(hr))
			{
				g_OscCache._hpal = hpal;
			}
		}
	}

	return TRUE;
}