DWORD
CDirect2DRMDevice::GetColor(BYTE r, BYTE g, BYTE b)
{
	HRESULT hr;
	if (m_pddsBackBuffer == NULL)
		return E_NOTINITIALIZED;

	// REVIEW: this function is heavy weight when the device is palettized
	DWORD nBPP = m_ddsd.ddpfPixelFormat.dwRGBBitCount;
	if (nBPP <= 8) {
		// palettized
		PALETTEENTRY rgpe[nMAXPALETTEENTRIES];
		LPDIRECTDRAWPALETTE pddp = NULL;
		if (FAILED(hr = m_pddsBackBuffer->GetPalette(&pddp)) ||
			FAILED(hr = pddp->GetEntries(0, 0, nMAXPALETTEENTRIES, rgpe))) {
			MMRELEASE(pddp);
			return hr;
		}
		MMRELEASE(pddp);
		return SimpleFindClosestIndex(rgpe, 1 << nBPP, r, g, b);
	} else {
		// RGB
		return m_pixi.Pack(r, g, b);
	}
	return 0;
}
示例#2
0
int PisteDraw_Paletti_Pyorita(UCHAR eka_vari, UCHAR vika_vari)
{
	UCHAR i;
	
	if (FAILED(PD_lpddpal->GetEntries(0,0,255,PD_paletti_nyt))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Palette get entries failed!\n");		
		return PD_VIRHE;
	}

	PALETTEENTRY temp_vari;
		
	temp_vari.peRed   = PD_paletti_nyt[vika_vari].peRed;
	temp_vari.peGreen = PD_paletti_nyt[vika_vari].peGreen;
	temp_vari.peBlue  = PD_paletti_nyt[vika_vari].peBlue;

	for (i=vika_vari;i>eka_vari;i--)
	{
		PD_paletti_nyt[i].peRed   = PD_paletti_nyt[i-1].peRed;
		PD_paletti_nyt[i].peGreen = PD_paletti_nyt[i-1].peGreen;
		PD_paletti_nyt[i].peBlue  = PD_paletti_nyt[i-1].peBlue;
	}

	PD_paletti_nyt[eka_vari].peRed   = temp_vari.peRed;
	PD_paletti_nyt[eka_vari].peGreen = temp_vari.peGreen;
	PD_paletti_nyt[eka_vari].peBlue  = temp_vari.peBlue;

	if (FAILED(PD_lpddpal->SetEntries(0,0,255,PD_paletti_nyt))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Palette set entries failed!\n");	
		return PD_VIRHE;	
	}
	
	return 0;
}
示例#3
0
int PisteDraw_Paletti_Get(PALETTEENTRY *&paletti)
{
	if (FAILED(PD_lpddpal->GetEntries(0,0,255,PD_paletti_nyt))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Palette get failed!\n");
		return PD_VIRHE;
	}

	paletti = (PALETTEENTRY *)PD_paletti_nyt;

	return 0;
}
示例#4
0
int PisteDraw_Fade_Paletti_Do(int pros)
{
	UCHAR i;
	
	if (FAILED(PD_lpddpal->GetEntries(0,0,255,PD_paletti_nyt))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Palette get entries failed!\n");
		return PD_VIRHE;
	}

	for (i=0;i<255;i++)
	{
		PD_paletti_nyt[i].peRed   = (PD_paletti[i].peRed   * pros / 100);
		PD_paletti_nyt[i].peGreen = (PD_paletti[i].peGreen * pros / 100);
		PD_paletti_nyt[i].peBlue  = (PD_paletti[i].peBlue  * pros / 100);
	}

	if (FAILED(PD_lpddpal->SetEntries(0,0,255,PD_paletti_nyt))) {
		PisteLog_Kirjoita("[Error] Piste Draw: Palette set entries failed!\n");
		return PD_VIRHE;
	}
	
	return 0;
}
示例#5
0
bool SetupPalette(LPDIRECTDRAWPALETTE lpDDPalette)
{
    if (!lpDDPalette)
    {
        //logOutput << CurrentTimeString() << "Detaching palette" << endl;
        g_CurrentPalette.Free();
        g_bUsePalette = false;
        return false;
    }

    logOutput << CurrentTimeString() << "initializing palette" << endl;

    DWORD caps;
    HRESULT hr;
    if (FAILED(hr = lpDDPalette->GetCaps(&caps)))
    {
        logOutput << CurrentTimeString() << "Failed to get palette caps" << endl;
        printDDrawError(hr, "SetupPalette");
        return false;
    }

    if (caps & DDPCAPS_8BITENTRIES)
    {
        logOutput << CurrentTimeString() << "8-bit index-palette used (lookup color is an index to another lookup table), not implemented" << endl;
        return false;
    }

    DWORD numEntries = 0;
    if (caps & DDPCAPS_8BIT)
        numEntries = 0x100;
    else if (caps & DDPCAPS_4BIT)
        numEntries = 0x10;
    else if (caps & DDPCAPS_2BIT)
        numEntries = 0x04;
    else if (caps & DDPCAPS_1BIT)
        numEntries = 0x02;
    else
    {
        logOutput << CurrentTimeString() << "Unrecognized palette format" << endl;
        return false;
    }

    //logOutput << CurrentTimeString() << "Trying to retrieve " << numEntries << " palette entries" << endl;

    g_CurrentPalette.Reallocate(numEntries);
    hr = lpDDPalette->GetEntries(0, 0, numEntries, g_CurrentPalette.entries);
    if (FAILED(hr))
    {
        logOutput << CurrentTimeString() << "Failed to retrieve palette entries" << endl;
        printDDrawError(hr, "SetupPalette");
        g_CurrentPalette.Free();
        return false;
    }

    g_CurrentPalette.primary_surface_palette_ref = lpDDPalette;
    g_CurrentPalette.bInitialized = true;
    g_bUsePalette = true;

    logOutput << CurrentTimeString() << "Initialized palette with " << numEntries << " color entries" << endl;

    return true;
}