|
|
1.1 ! root 1: /******************************Module*Header*******************************\ ! 2: * Module Name: palette.c ! 3: * ! 4: * Palette support. ! 5: * ! 6: * Copyright (c) 1992 Microsoft Corporation ! 7: \**************************************************************************/ ! 8: ! 9: #include "driver.h" ! 10: ! 11: // Global Table defining the 20 Window Default Colors. For 256 color ! 12: // palettes the first 10 must be put at the beginning of the palette ! 13: // and the last 10 at the end of the palette. ! 14: ! 15: const PALETTEENTRY BASEPALETTE[20] = ! 16: { ! 17: { 0, 0, 0, 0 }, // 0 ! 18: { 0x80,0, 0, 0 }, // 1 ! 19: { 0, 0x80,0, 0 }, // 2 ! 20: { 0x80,0x80,0, 0 }, // 3 ! 21: { 0, 0, 0x80,0 }, // 4 ! 22: { 0x80,0, 0x80,0 }, // 5 ! 23: { 0, 0x80,0x80,0 }, // 6 ! 24: { 0xC0,0xC0,0xC0,0 }, // 7 ! 25: { 192, 220, 192, 0 }, // 8 ! 26: { 166, 202, 240, 0 }, // 9 ! 27: { 255, 251, 240, 0 }, // 10 ! 28: { 160, 160, 164, 0 }, // 11 ! 29: { 0x80,0x80,0x80,0 }, // 12 ! 30: { 0xFF,0, 0 ,0 }, // 13 ! 31: { 0, 0xFF,0 ,0 }, // 14 ! 32: { 0xFF,0xFF,0 ,0 }, // 15 ! 33: { 0 ,0, 0xFF,0 }, // 16 ! 34: { 0xFF,0, 0xFF,0 }, // 17 ! 35: { 0, 0xFF,0xFF,0 }, // 18 ! 36: { 0xFF,0xFF,0xFF,0 }, // 19 ! 37: }; ! 38: ! 39: BOOL bInitDefaultPalette(PPDEV ppdev); ! 40: ! 41: /******************************Public*Routine******************************\ ! 42: * bInitPaletteInfo ! 43: * ! 44: * Initializes the palette information for this PDEV. ! 45: * ! 46: * Called by DrvEnablePDEV. ! 47: * ! 48: \**************************************************************************/ ! 49: ! 50: BOOL bInitPaletteInfo(PPDEV ppdev) ! 51: { ! 52: if (!bInitDefaultPalette(ppdev)) ! 53: return(FALSE); ! 54: ! 55: return(TRUE); ! 56: } ! 57: ! 58: /******************************Public*Routine******************************\ ! 59: * vDisablePalette ! 60: * ! 61: * Frees resources allocated by bInitPaletteInfo. ! 62: * ! 63: \**************************************************************************/ ! 64: ! 65: VOID vDisablePalette(PPDEV ppdev) ! 66: { ! 67: // Delete the default palette if we created one. ! 68: ! 69: if (ppdev->hpalDefault) ! 70: { ! 71: EngDeletePalette(ppdev->hpalDefault); ! 72: ppdev->hpalDefault = (HPALETTE) 0; ! 73: } ! 74: ! 75: if (ppdev->pPal != (PPALETTEENTRY)NULL) ! 76: LocalFree((PVOID)ppdev->pPal); ! 77: } ! 78: ! 79: /******************************Public*Routine******************************\ ! 80: * bInitDefaultPalette ! 81: * ! 82: * Initializes default palette for PDEV. ! 83: * ! 84: \**************************************************************************/ ! 85: ! 86: BOOL bInitDefaultPalette(PPDEV ppdev) ! 87: { ! 88: if (ppdev->ulBitCount == 8) ! 89: { ! 90: ULONG ulLoop; ! 91: BYTE jRed,jGre,jBlu; ! 92: ! 93: // Allocate our palette ! 94: ! 95: ppdev->pPal = (PPALETTEENTRY)LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, ! 96: (sizeof(PALETTEENTRY) * 256)); ! 97: ! 98: if ((ppdev->pPal) == NULL) { ! 99: DISPDBG((0, "S3.DLL!bInitDefaultPalette - LocalAlloc failed \n")); ! 100: EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); ! 101: return (FALSE); ! 102: } ! 103: ! 104: ! 105: // Generate 256 (8*4*4) RGB combinations to fill the palette ! 106: ! 107: jRed = jGre = jBlu = 0; ! 108: ! 109: for (ulLoop = 0; ulLoop < 256; ulLoop++) ! 110: { ! 111: ppdev->pPal[ulLoop].peRed = jRed; ! 112: ppdev->pPal[ulLoop].peGreen = jGre; ! 113: ppdev->pPal[ulLoop].peBlue = jBlu; ! 114: ppdev->pPal[ulLoop].peFlags = (BYTE)0; ! 115: ! 116: if (!(jRed += 32)) ! 117: if (!(jGre += 32)) ! 118: jBlu += 64; ! 119: } ! 120: ! 121: // Fill in Windows Reserved Colors from the WIN 3.0 DDK ! 122: // The Window Manager reserved the first and last 10 colors for ! 123: // painting windows borders and for non-palette managed applications. ! 124: ! 125: for (ulLoop = 0; ulLoop < 10; ulLoop++) ! 126: { ! 127: // First 10 ! 128: ! 129: ppdev->pPal[ulLoop] = BASEPALETTE[ulLoop]; ! 130: ! 131: // Last 10 ! 132: ! 133: ppdev->pPal[246 + ulLoop] = BASEPALETTE[ulLoop+10]; ! 134: } ! 135: ! 136: // Create handle for palette. ! 137: ! 138: ppdev->hpalDefault = ! 139: ppdev->pDevInfo->hpalDefault = EngCreatePalette(PAL_INDEXED, ! 140: 256, ! 141: (PULONG) ppdev->pPal, ! 142: 0,0,0); ! 143: ! 144: if (ppdev->hpalDefault == (HPALETTE) 0) ! 145: { ! 146: DISPDBG((0, "DISP bInitDefaultPalette failed EngCreatePalette\n")); ! 147: LocalFree(ppdev->pPal); ! 148: return(FALSE); ! 149: } ! 150: ! 151: // Initialize the hardware with the initial palette. ! 152: ! 153: return(TRUE); ! 154: } ! 155: else if (ppdev->ulBitCount == 16) ! 156: { ! 157: ppdev->hpalDefault = ! 158: ppdev->pDevInfo->hpalDefault = EngCreatePalette(PAL_BITFIELDS, ! 159: 0, ! 160: (PULONG) NULL, ! 161: ppdev->flRed, ! 162: ppdev->flGreen, ! 163: ppdev->flBlue); ! 164: ! 165: if (ppdev->hpalDefault == (HPALETTE) 0) ! 166: { ! 167: DISPDBG((0, "DISP bInitDefaultPalette failed EngCreatePalette\n")); ! 168: return(FALSE); ! 169: } ! 170: } ! 171: else ! 172: { ! 173: RIP("S3.DLL!bInitDefaultPalette - ppdev->ulBitCount is invalid\n"); ! 174: return (FALSE); ! 175: } ! 176: ! 177: return(TRUE); ! 178: } ! 179: ! 180: /******************************Public*Routine******************************\ ! 181: * bInit256ColorPalette ! 182: * ! 183: * Initialize the hardware's palette registers. ! 184: * ! 185: \**************************************************************************/ ! 186: ! 187: BOOL bInit256ColorPalette(PPDEV ppdev) ! 188: { ! 189: BYTE ajClutSpace[MAX_CLUT_SIZE]; ! 190: PVIDEO_CLUT pScreenClut = (PVIDEO_CLUT) ajClutSpace; ! 191: ULONG ulReturnedDataLength; ! 192: ! 193: // Fill in pScreenClut header info ! 194: pScreenClut->NumEntries = 256; ! 195: pScreenClut->FirstEntry = 0; ! 196: ! 197: ! 198: // Copy Colors in. ! 199: memcpy(pScreenClut->LookupTable, ppdev->pPal, sizeof(ULONG) * 256); ! 200: ! 201: // Set palette registers ! 202: if (!DeviceIoControl(ppdev->hDriver, ! 203: IOCTL_VIDEO_SET_COLOR_REGISTERS, ! 204: pScreenClut, ! 205: MAX_CLUT_SIZE, ! 206: NULL, ! 207: 0, ! 208: &ulReturnedDataLength, ! 209: NULL)) ! 210: { ! 211: DISPDBG((0, "DISP bInit256ColorPalette failed DeviceIoControl\n")); ! 212: return(FALSE); ! 213: } ! 214: ! 215: return(TRUE); ! 216: } ! 217: ! 218: /******************************Public*Routine******************************\ ! 219: * DrvSetPalette ! 220: * ! 221: * DDI entry point for manipulating the palette. ! 222: * ! 223: \**************************************************************************/ ! 224: ! 225: BOOL DrvSetPalette( ! 226: DHPDEV dhpdev, ! 227: PALOBJ *ppalo, ! 228: FLONG fl, ! 229: ULONG iStart, ! 230: ULONG cColors) ! 231: { ! 232: BYTE ajClutSpace[MAX_CLUT_SIZE]; ! 233: PVIDEO_CLUT pScreenClut = (PVIDEO_CLUT) ajClutSpace; ! 234: PPALETTEENTRY pape; ! 235: ULONG ulTemp = 256; ! 236: ! 237: UNREFERENCED_PARAMETER(fl); ! 238: ! 239: // Fill in pScreenClut header info ! 240: ! 241: pScreenClut->NumEntries = (USHORT) cColors; ! 242: pScreenClut->FirstEntry = (USHORT) iStart; ! 243: ! 244: pape = (PPALETTEENTRY) (pScreenClut->LookupTable); ! 245: ! 246: if (cColors != PALOBJ_cGetColors(ppalo, iStart, cColors, (PULONG) pape)) ! 247: { ! 248: DISPDBG((0, "DISP DrvSetPalette failed PALOBJ_cGetColors\n")); ! 249: return(FALSE); ! 250: } ! 251: ! 252: // Set the high reserved byte in each palette entry to 0. ! 253: ! 254: while(cColors--) ! 255: pape[cColors].peFlags = 0; ! 256: ! 257: // Set palette registers ! 258: ! 259: if (!DeviceIoControl(((PPDEV)(dhpdev))->hDriver, ! 260: IOCTL_VIDEO_SET_COLOR_REGISTERS, ! 261: pScreenClut, ! 262: MAX_CLUT_SIZE, ! 263: NULL, ! 264: 0, ! 265: &cColors, ! 266: NULL)) ! 267: { ! 268: DISPDBG((0, "DISP DrvSetPalette failed DeviceIoControl\n")); ! 269: return(FALSE); ! 270: } ! 271: ! 272: return(TRUE); ! 273: } ! 274:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.