You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
372 lines
11 KiB
372 lines
11 KiB
/******************************Module*Header*******************************\
|
|
*
|
|
* *******************
|
|
* * GDI SAMPLE CODE *
|
|
* *******************
|
|
*
|
|
* Module Name: palette.c
|
|
*
|
|
* Palette support.
|
|
*
|
|
* Copyright (c) 1992-1998 Microsoft Corporation
|
|
\**************************************************************************/
|
|
|
|
#include "precomp.h"
|
|
|
|
// Global Table defining the 20 Window default colours. For 256 colour
|
|
// palettes the first 10 must be put at the beginning of the palette
|
|
// and the last 10 at the end of the palette.
|
|
|
|
PALETTEENTRY gapalBase[20] =
|
|
{
|
|
{ 0, 0, 0, 0 }, // 0
|
|
{ 0x80,0, 0, 0 }, // 1
|
|
{ 0, 0x80,0, 0 }, // 2
|
|
{ 0x80,0x80,0, 0 }, // 3
|
|
{ 0, 0, 0x80,0 }, // 4
|
|
{ 0x80,0, 0x80,0 }, // 5
|
|
{ 0, 0x80,0x80,0 }, // 6
|
|
{ 0xC0,0xC0,0xC0,0 }, // 7
|
|
{ 192, 220, 192, 0 }, // 8
|
|
{ 166, 202, 240, 0 }, // 9
|
|
{ 255, 251, 240, 0 }, // 10
|
|
{ 160, 160, 164, 0 }, // 11
|
|
{ 0x80,0x80,0x80,0 }, // 12
|
|
{ 0xFF,0, 0 ,0 }, // 13
|
|
{ 0, 0xFF,0 ,0 }, // 14
|
|
{ 0xFF,0xFF,0 ,0 }, // 15
|
|
{ 0 ,0, 0xFF,0 }, // 16
|
|
{ 0xFF,0, 0xFF,0 }, // 17
|
|
{ 0, 0xFF,0xFF,0 }, // 18
|
|
{ 0xFF,0xFF,0xFF,0 }, // 19
|
|
};
|
|
|
|
/******************************Public*Routine******************************\
|
|
* BOOL bInitializePalette
|
|
*
|
|
* Initializes default palette for PDEV.
|
|
*
|
|
\**************************************************************************/
|
|
|
|
BOOL bInitializePalette(
|
|
PDEV* ppdev,
|
|
DEVINFO* pdi)
|
|
{
|
|
PALETTEENTRY* ppal;
|
|
PALETTEENTRY* ppalTmp;
|
|
ULONG ulLoop;
|
|
HPALETTE hpal;
|
|
|
|
if (ppdev->iBitmapFormat == BMF_8BPP)
|
|
{
|
|
// Allocate our palette:
|
|
|
|
ppal = EngAllocMem(FL_ZERO_MEMORY, sizeof(PALETTEENTRY) * 256, ALLOC_TAG);
|
|
if (ppal == NULL)
|
|
goto ReturnFalse;
|
|
|
|
ppdev->pPal = ppal;
|
|
|
|
// Fill in Windows reserved colours from the WIN 3.0 DDK
|
|
// The Window Manager reserved the first and last 10 colours for
|
|
// painting windows borders and for non-palette managed applications.
|
|
|
|
for (ulLoop = 0; ulLoop < 10; ulLoop++)
|
|
{
|
|
// First 10
|
|
|
|
ppal[ulLoop] = gapalBase[ulLoop];
|
|
|
|
// Last 10
|
|
|
|
ppal[246 + ulLoop] = gapalBase[ulLoop+10];
|
|
}
|
|
|
|
// Create handle for palette.
|
|
|
|
hpal = EngCreatePalette(PAL_INDEXED, 256, (ULONG*) ppal, 0, 0, 0);
|
|
}
|
|
else
|
|
{
|
|
ASSERTDD((ppdev->iBitmapFormat == BMF_16BPP) ||
|
|
(ppdev->iBitmapFormat == BMF_24BPP) ||
|
|
(ppdev->iBitmapFormat == BMF_32BPP),
|
|
"This case handles only 16, 24 or 32bpp");
|
|
|
|
hpal = EngCreatePalette(PAL_BITFIELDS, 0, NULL,
|
|
ppdev->flRed, ppdev->flGreen, ppdev->flBlue);
|
|
}
|
|
|
|
ppdev->hpalDefault = hpal;
|
|
pdi->hpalDefault = hpal;
|
|
|
|
if (hpal == 0)
|
|
goto ReturnFalse;
|
|
|
|
return(TRUE);
|
|
|
|
ReturnFalse:
|
|
|
|
DISPDBG((0, "Failed bInitializePalette"));
|
|
return(FALSE);
|
|
}
|
|
|
|
/******************************Public*Routine******************************\
|
|
* VOID vUninitializePalette
|
|
*
|
|
* Frees resources allocated by bInitializePalette.
|
|
*
|
|
* Note: In an error case, this may be called before bInitializePalette.
|
|
*
|
|
\**************************************************************************/
|
|
|
|
VOID vUninitializePalette(PDEV* ppdev)
|
|
{
|
|
// Delete the default palette if we created one:
|
|
|
|
if (ppdev->hpalDefault != 0)
|
|
EngDeletePalette(ppdev->hpalDefault);
|
|
|
|
if (ppdev->pPal != (PALETTEENTRY*) NULL)
|
|
EngFreeMem(ppdev->pPal);
|
|
}
|
|
|
|
/******************************Public*Routine******************************\
|
|
* BOOL bEnablePalette
|
|
*
|
|
* Initialize the hardware's 8bpp palette registers.
|
|
*
|
|
\**************************************************************************/
|
|
|
|
BOOL bEnablePalette(PDEV* ppdev)
|
|
{
|
|
BYTE ajClutSpace[MAX_CLUT_SIZE];
|
|
PVIDEO_CLUT pScreenClut;
|
|
ULONG ulReturnedDataLength;
|
|
ULONG cColors;
|
|
PVIDEO_CLUTDATA pScreenClutData;
|
|
|
|
if (ppdev->iBitmapFormat == BMF_8BPP)
|
|
{
|
|
// Fill in pScreenClut header info:
|
|
|
|
pScreenClut = (PVIDEO_CLUT) ajClutSpace;
|
|
pScreenClut->NumEntries = 256;
|
|
pScreenClut->FirstEntry = 0;
|
|
|
|
// Copy colours in:
|
|
|
|
cColors = 256;
|
|
pScreenClutData = (PVIDEO_CLUTDATA) (&(pScreenClut->LookupTable[0]));
|
|
|
|
while(cColors--)
|
|
{
|
|
pScreenClutData[cColors].Red = ppdev->pPal[cColors].peRed >>
|
|
ppdev->cPaletteShift;
|
|
pScreenClutData[cColors].Green = ppdev->pPal[cColors].peGreen >>
|
|
ppdev->cPaletteShift;
|
|
pScreenClutData[cColors].Blue = ppdev->pPal[cColors].peBlue >>
|
|
ppdev->cPaletteShift;
|
|
pScreenClutData[cColors].Unused = 0;
|
|
}
|
|
|
|
// Set palette registers:
|
|
|
|
if (EngDeviceIoControl(ppdev->hDriver,
|
|
IOCTL_VIDEO_SET_COLOR_REGISTERS,
|
|
pScreenClut,
|
|
MAX_CLUT_SIZE,
|
|
NULL,
|
|
0,
|
|
&ulReturnedDataLength))
|
|
{
|
|
DISPDBG((0, "Failed bEnablePalette"));
|
|
return(FALSE);
|
|
}
|
|
}
|
|
|
|
DISPDBG((5, "Passed bEnablePalette"));
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
/******************************Public*Routine******************************\
|
|
* VOID vDisablePalette
|
|
*
|
|
* Undoes anything done in bEnablePalette.
|
|
*
|
|
\**************************************************************************/
|
|
|
|
VOID vDisablePalette(
|
|
PDEV* ppdev)
|
|
{
|
|
// Nothin' to do
|
|
}
|
|
|
|
/******************************Public*Routine******************************\
|
|
* VOID vAssertModePalette
|
|
*
|
|
* Sets/resets the palette in preparation for full-screen/graphics mode.
|
|
*
|
|
\**************************************************************************/
|
|
|
|
VOID vAssertModePalette(
|
|
PDEV* ppdev,
|
|
BOOL bEnable)
|
|
{
|
|
// USER immediately calls DrvSetPalette after switching out of
|
|
// full-screen, so we don't have to worry about resetting the
|
|
// palette here.
|
|
}
|
|
|
|
/******************************Public*Routine******************************\
|
|
* BOOL DrvSetPalette
|
|
*
|
|
* DDI entry point for manipulating the palette.
|
|
*
|
|
\**************************************************************************/
|
|
|
|
BOOL DrvSetPalette(
|
|
DHPDEV dhpdev,
|
|
PALOBJ* ppalo,
|
|
FLONG fl,
|
|
ULONG iStart,
|
|
ULONG cColors)
|
|
{
|
|
BYTE ajClutSpace[MAX_CLUT_SIZE];
|
|
PVIDEO_CLUT pScreenClut;
|
|
PVIDEO_CLUTDATA pScreenClutData;
|
|
PDEV* ppdev;
|
|
|
|
UNREFERENCED_PARAMETER(fl);
|
|
|
|
ppdev = (PDEV*) dhpdev;
|
|
|
|
// Fill in pScreenClut header info:
|
|
|
|
pScreenClut = (PVIDEO_CLUT) ajClutSpace;
|
|
pScreenClut->NumEntries = (USHORT) cColors;
|
|
pScreenClut->FirstEntry = (USHORT) iStart;
|
|
|
|
pScreenClutData = (PVIDEO_CLUTDATA) (&(pScreenClut->LookupTable[0]));
|
|
|
|
if (cColors != PALOBJ_cGetColors(ppalo, iStart, cColors,
|
|
(ULONG*) pScreenClutData))
|
|
{
|
|
DISPDBG((0, "DrvSetPalette failed PALOBJ_cGetColors"));
|
|
return (FALSE);
|
|
}
|
|
|
|
// Set the high reserved byte in each palette entry to 0.
|
|
// Do the appropriate palette shifting to fit in the DAC.
|
|
|
|
if (ppdev->cPaletteShift)
|
|
{
|
|
while(cColors--)
|
|
{
|
|
pScreenClutData[cColors].Red >>= ppdev->cPaletteShift;
|
|
pScreenClutData[cColors].Green >>= ppdev->cPaletteShift;
|
|
pScreenClutData[cColors].Blue >>= ppdev->cPaletteShift;
|
|
pScreenClutData[cColors].Unused = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
while(cColors--)
|
|
{
|
|
pScreenClutData[cColors].Unused = 0;
|
|
}
|
|
}
|
|
|
|
// Set palette registers
|
|
|
|
if (EngDeviceIoControl(ppdev->hDriver,
|
|
IOCTL_VIDEO_SET_COLOR_REGISTERS,
|
|
pScreenClut,
|
|
MAX_CLUT_SIZE,
|
|
NULL,
|
|
0,
|
|
&cColors))
|
|
{
|
|
DISPDBG((0, "DrvSetPalette failed SET_COLOR_REGISTERS"));
|
|
return (FALSE);
|
|
}
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
/******************************Public*Routine******************************\
|
|
* BOOL DrvIcmSetDeviceGammaRamp
|
|
*
|
|
* DDI entry point for manipulating the device gamma ramp.
|
|
*
|
|
* Note that GCAPS2_CHANGEGAMMARAMP has to be set for this to be called.
|
|
* Don't set GCAPS2_CHANGEGAMMARAMP when running 8bpp, though!
|
|
*
|
|
* (Note that we currently aren't hooking this call because none of the
|
|
* S3 hardware supports it!)
|
|
*
|
|
\**************************************************************************/
|
|
|
|
BOOL DrvIcmSetDeviceGammaRamp(
|
|
DHPDEV dhpdev,
|
|
ULONG iFormat,
|
|
PVOID lpRamp)
|
|
{
|
|
BYTE ajClutSpace[MAX_CLUT_SIZE];
|
|
PVIDEO_CLUT pScreenClut;
|
|
PVIDEO_CLUTDATA pScreenClutData;
|
|
PGAMMARAMP pGammaRamp;
|
|
PDEV* ppdev;
|
|
ULONG i;
|
|
DWORD cColors;
|
|
BYTE* pjIoBase;
|
|
BYTE jMode;
|
|
BYTE jDacControl;
|
|
|
|
ppdev = (PDEV*) dhpdev;
|
|
|
|
pjIoBase = ppdev->pjIoBase;
|
|
|
|
// Fill in pScreenClut header info:
|
|
|
|
pScreenClut = (PVIDEO_CLUT) ajClutSpace;
|
|
pScreenClut->NumEntries = (USHORT) 256;
|
|
pScreenClut->FirstEntry = (USHORT) 0;
|
|
|
|
pScreenClutData = (PVIDEO_CLUTDATA) (&(pScreenClut->LookupTable[0]));
|
|
|
|
pGammaRamp = lpRamp;
|
|
|
|
if (iFormat == IGRF_RGB_256WORDS)
|
|
{
|
|
for (i = 0; i < 256; i++)
|
|
{
|
|
// The gamma-ramp colors are given to us in an 8.8 fixed
|
|
// point format. Since our DAC has only 8 bits of color
|
|
// precision, we get rid of the fractional part by simple
|
|
// truncation.
|
|
|
|
pScreenClutData[i].Red = pGammaRamp->Red[i] >> 8;
|
|
pScreenClutData[i].Green = pGammaRamp->Green[i] >> 8;
|
|
pScreenClutData[i].Blue = pGammaRamp->Blue[i] >> 8;
|
|
pScreenClutData[i].Unused = 0;
|
|
}
|
|
|
|
// Set palette registers:
|
|
|
|
if (EngDeviceIoControl(ppdev->hDriver,
|
|
IOCTL_VIDEO_SET_COLOR_REGISTERS,
|
|
pScreenClut,
|
|
MAX_CLUT_SIZE,
|
|
NULL,
|
|
0,
|
|
&cColors))
|
|
{
|
|
DISPDBG((0, "DrvIcmSetDeviceGammaRamp failed SET_COLOR_REGISTERS"));
|
|
return (FALSE);
|
|
}
|
|
}
|
|
|
|
return(TRUE);
|
|
}
|