⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 palette.cpp

📁 WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
💻 CPP
字号:
#include "precomp.h"
#include "mqmacro.h"

#include "palette.h"							// For palette-aware modes
INSTANTIATE_PALETTE_256
INSTANTIATE_PALETTE_16
INSTANTIATE_PALETTE_4
INSTANTIATE_PALETTE_2

ULONG BitMasks16[] 		= { 0xF800,0x07E0,0x001F };
ULONG BitMasks24[] 		= { 0xFF0000,0x00FF00,0x0000FF };
ULONG BitMasks32[] 		= { 0x0000FF,0x00FF00,0xFF0000 };
ULONG BitMasks_Pal[] = { 0,0,0 };

extern USHORT usBPP;

// Since we enable Color Palette Write Control (CPUCNTL[0]), the RGB data
// in both palettes will be in sync automatically. The configuration to
// run LCD and CRT at different color depth is not supported, there is no
// need to do extra checking other than slam RGB data to DAC.
//

SCODE MQGC::SetPalette(
	const PALETTEENTRY *src,
	unsigned short firstEntry,
	unsigned short numEntries )
{
	ULONG ulRGB, ulRGBIn;

	//RETAILMSG(1,(TEXT("MQGC::SetPalette,1st=%x,num=%x\r\n"),
	//		firstEntry,numEntries));

	if( firstEntry < 0 || firstEntry + numEntries > 256 )
		return E_INVALIDARG;

	// Enable Int mask for GC1 VDE Falling Edge 
	//
	intREG(INT_MASK_REG,UM_GC1_VDE_F);
	while (InVBlank());	    // wait for current VBLank to be over
	while (!InVBlank());	// wait for next VBlank to start


	if (m_nMQFlag & GAMMA_ENABLED)
	{
		for( ; numEntries; numEntries-- )
		{
			ulRGBIn = *((ULONG *)src);
			ulRGB = m_nGammaRGB[ulRGBIn & 0x000000ff] & 0x000000ff; // R
			ulRGB |= m_nGammaRGB[(ulRGBIn & 0x0000ff00) >> 8] & 0x0000ff00; //G
			ulRGB |= m_nGammaRGB[(ulRGBIn & 0x00ff0000) >> 16] & 0x00ff0000; //B
			palREG(firstEntry++, ulRGB);	// RGB at one shot
			src++;
		}
	}
	else
	{
		for( ; numEntries; numEntries-- )
		{
			palREG(firstEntry++, *((ULONG *)src));	// RGB at one shot
			src++;
		}
	}

	// Reset Int mask for GC1 VDE Falling Edge
	//
	intREG(INT_MASK_REG,0);
	DumpPal();	// no op for non-emulation

	return S_OK;
}

void MQGC::SetHWPalette(
	ULONG *src,
	unsigned short firstEntry,
	unsigned short numEntries )
{

	// Enable Int mask for GC1 VDE Falling Edge for DAC access
	//
	intREG(INT_MASK_REG,UM_GC1_VDE_F);
	while (InVBlank());	    // wait for current VBLank to be over
	while (!InVBlank());	// wait for next VBlank to start


	if( usBPP == 8)
	{
		for( ; numEntries; numEntries-- )
		{
			m_nGammaRGB[firstEntry] = *src;	// Update gamma mapping table
			firstEntry++;
			src++;
		}
		SetPalette( _rgbIdentity256, 0, 256);
		return;
	}
	if( usBPP > 8)
	{
		for( ; numEntries; numEntries-- )
		{
			m_nGammaRGB[firstEntry] = *src;	// Update gamma mapping table
			palREG(firstEntry++, *((ULONG *)src));	// RGB at one shot
			src++;
		}
	}
	
	// Reset Int mask for GC1 VDE Falling Edge
	//
	intREG(INT_MASK_REG,0);
}

void MQGC::CreatePal(HPALETTE *pPalette )
{
	ULONG *src;
	int i;

	// Here, we use EngCreatePalette to create a palette that that MGDI will use as a
	// stock palette
	//
	switch (m_ulBPP)
	{
		// For 1/2/4/8 BPP modes, they are all palette-aware modes
		//
		case 1 :
			*pPalette = EngCreatePalette
						(
							PAL_INDEXED,
							2,
							(ULONG *)_rgbIdentity2,
							0,
							0,
							0
						);
			src = (ULONG *)_rgbIdentity2;
			for (i=0; i<2; i++)
			{
				palREG(i, *src);
				src++;
			}
			break;

		case 2 :
			*pPalette = EngCreatePalette
						(
							PAL_INDEXED,
							4,
							(ULONG *)_rgbIdentity4,
							0,
							0,
							0
						);
			src = (ULONG *)_rgbIdentity4;
			for (i=0; i<4; i++)
			{
				palREG(i, *src);
				src++;
			}
			break;

		case 4 :
			*pPalette = EngCreatePalette
						(
							PAL_INDEXED,
							16,
							(ULONG *)_rgbIdentity16,
							0,
							0,
							0
						);
			src = (ULONG *)_rgbIdentity16;
			for (i=0; i<16; i++)
			{
				palREG(i, *src);
				src++;
			}
			break;

		case 8 :
			*pPalette = EngCreatePalette
						(
							PAL_INDEXED,
							256,
							(ULONG *)_rgbIdentity256,
							0,
							0,
							0
						);
			break;

		case 16 :
			// 15,16,24, and 32bpp primaries are defined by red, green, and 
			// blue bitfields...
			//
			*pPalette = EngCreatePalette
						(
							PAL_BITFIELDS,
							0, 
							NULL,
							BitMasks16[0],
							BitMasks16[1],
							BitMasks16[2]
						);
			break;

		case 24 :
			// 15,16,24, and 32bpp primaries are defined by red, green, and 
			// blue bitfields...
			//
			*pPalette = EngCreatePalette
						(
							PAL_BITFIELDS,
							0, 
							NULL,
							BitMasks24[0],
							BitMasks24[1],
							BitMasks24[2]
						);
			break;

		case 32 :
			// 15,16,24, and 32bpp primaries are defined by red, green, and 
			// blue bitfields...
			//
			*pPalette = EngCreatePalette
						(
							PAL_BITFIELDS,
							0, 
							NULL,
							BitMasks32[0],
							BitMasks32[1],
							BitMasks32[2]
						);
			break;

		default :
			; // error here
	}
}	

ULONG *APIENTRY DrvGetMasks(
    DHPDEV     dhpdev)
{
	switch(usBPP)
	{
		case 16:
			return BitMasks16;

		case 24:
			return BitMasks24;

		case 32:
			return BitMasks32;

		default:
			return BitMasks_Pal;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -