Annotation of ntddk/src/video/displays/framebuf/palette.c, revision 1.1.1.1

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, DEVINFO *pDevInfo);
                     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, DEVINFO *pDevInfo)
                     51: {
                     52:     if (!bInitDefaultPalette(ppdev, pDevInfo))
                     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, DEVINFO *pDevInfo)
                     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:             RIP("DISP bInitDefaultPalette() failed LocalAlloc\n");
                    100:             return(FALSE);
                    101:         }
                    102: 
                    103: 
                    104:         // Generate 256 (8*4*4) RGB combinations to fill the palette
                    105: 
                    106:         jRed = jGre = jBlu = 0;
                    107: 
                    108:         for (ulLoop = 0; ulLoop < 256; ulLoop++)
                    109:         {
                    110:             ppdev->pPal[ulLoop].peRed   = jRed;
                    111:             ppdev->pPal[ulLoop].peGreen = jGre;
                    112:             ppdev->pPal[ulLoop].peBlue  = jBlu;
                    113:             ppdev->pPal[ulLoop].peFlags = (BYTE)0;
                    114: 
                    115:             if (!(jRed += 32))
                    116:             if (!(jGre += 32))
                    117:             jBlu += 64;
                    118:         }
                    119: 
                    120:     // Fill in Windows Reserved Colors from the WIN 3.0 DDK
                    121:     // The Window Manager reserved the first and last 10 colors for
                    122:     // painting windows borders and for non-palette managed applications.
                    123: 
                    124:         for (ulLoop = 0; ulLoop < 10; ulLoop++)
                    125:         {
                    126:         // First 10
                    127: 
                    128:             ppdev->pPal[ulLoop] = BASEPALETTE[ulLoop];
                    129: 
                    130:         // Last 10
                    131: 
                    132:             ppdev->pPal[246 + ulLoop] = BASEPALETTE[ulLoop+10];
                    133:         }
                    134: 
                    135:     // Create handle for palette.
                    136: 
                    137:         ppdev->hpalDefault =
                    138:         pDevInfo->hpalDefault = EngCreatePalette(PAL_INDEXED,
                    139:                                                    256,
                    140:                                                    (PULONG) ppdev->pPal,
                    141:                                                    0,0,0);
                    142: 
                    143:         if (ppdev->hpalDefault == (HPALETTE) 0)
                    144:         {
                    145:             RIP("DISP bInitDefaultPalette failed EngCreatePalette\n");
                    146:             LocalFree(ppdev->pPal);
                    147:             return(FALSE);
                    148:         }
                    149: 
                    150:     // Initialize the hardware with the initial palette.
                    151: 
                    152:         return(TRUE);
                    153:     } else {
                    154: 
                    155:         ppdev->hpalDefault =
                    156:         pDevInfo->hpalDefault = EngCreatePalette(PAL_BITFIELDS,
                    157:                                                    0,(PULONG) NULL,
                    158:                                                    ppdev->flRed,
                    159:                                                    ppdev->flGreen,
                    160:                                                    ppdev->flBlue);
                    161: 
                    162:         if (ppdev->hpalDefault == (HPALETTE) 0)
                    163:         {
                    164:             RIP("DISP bInitDefaultPalette failed EngCreatePalette\n");
                    165:             return(FALSE);
                    166:         }
                    167:     }
                    168: 
                    169:     return(TRUE);
                    170: }
                    171: 
                    172: /******************************Public*Routine******************************\
                    173: * bInit256ColorPalette
                    174: *
                    175: * Initialize the hardware's palette registers.
                    176: *
                    177: \**************************************************************************/
                    178: 
                    179: BOOL bInit256ColorPalette(PPDEV ppdev)
                    180: {
                    181:     BYTE ajClutSpace[MAX_CLUT_SIZE];
                    182:     PVIDEO_CLUT pScreenClut = (PVIDEO_CLUT) ajClutSpace;
                    183:     ULONG  ulReturnedDataLength;
                    184: 
                    185:     // Fill in pScreenClut header info
                    186:     pScreenClut->NumEntries = 256;
                    187:     pScreenClut->FirstEntry = 0;
                    188: 
                    189:     // make sure that we have a palette
                    190:     if (ppdev->pPal == NULL)
                    191:     {
                    192:         RIP("DISP bInit256ColorPalette -- pPal == NULL\n");
                    193:         return(FALSE);
                    194:     }
                    195: 
                    196:     // Copy Colors in.
                    197:     RtlCopyMemory(pScreenClut->LookupTable, ppdev->pPal, sizeof(ULONG) * 256);
                    198: 
                    199:     // Set palette registers
                    200:     if (!DeviceIoControl(ppdev->hDriver,
                    201:                          IOCTL_VIDEO_SET_COLOR_REGISTERS,
                    202:                          pScreenClut,
                    203:                          MAX_CLUT_SIZE,
                    204:                          NULL,
                    205:                          0,
                    206:                          &ulReturnedDataLength,
                    207:                          NULL))
                    208:     {
                    209:         RIP("DISP bInit256ColorPalette failed DeviceIoControl\n");
                    210:         return(FALSE);
                    211:     }
                    212: 
                    213:     return(TRUE);
                    214: }
                    215: 
                    216: /******************************Public*Routine******************************\
                    217: * DrvSetPalette
                    218: *
                    219: * DDI entry point for manipulating the palette.
                    220: *
                    221: \**************************************************************************/
                    222: 
                    223: BOOL DrvSetPalette(
                    224: IN DHPDEV dhpdev,
                    225: IN PALOBJ *ppalo,
                    226: IN FLONG  fl,
                    227: IN ULONG  iStart,
                    228: IN ULONG  cColors)
                    229: {
                    230:     BYTE ajClutSpace[MAX_CLUT_SIZE];
                    231:     PVIDEO_CLUT pScreenClut = (PVIDEO_CLUT) ajClutSpace;
                    232:     PPALETTEENTRY pape;
                    233:     ULONG ulTemp = 256;
                    234: 
                    235:     UNREFERENCED_PARAMETER(fl);
                    236: 
                    237: // Fill in pScreenClut header info
                    238: 
                    239:     pScreenClut->NumEntries = cColors;
                    240:     pScreenClut->FirstEntry = iStart;
                    241: 
                    242:     pape = (PPALETTEENTRY) (pScreenClut->LookupTable);
                    243: 
                    244:     if (cColors != PALOBJ_cGetColors(ppalo, iStart, cColors, (PULONG) pape))
                    245:     {
                    246:         RIP("DISP DrvSetPalette failed PALOBJ_cGetColors\n");
                    247:         return(FALSE);
                    248:     }
                    249: 
                    250: // Set the high reserved byte in each palette entry to 0.
                    251: 
                    252:     while(cColors--)
                    253:         pape[cColors].peFlags = 0;
                    254: 
                    255: // Set palette registers
                    256: 
                    257:     if (!DeviceIoControl(((PPDEV)(dhpdev))->hDriver,
                    258:                           IOCTL_VIDEO_SET_COLOR_REGISTERS,
                    259:                           pScreenClut,
                    260:                           MAX_CLUT_SIZE,
                    261:                           NULL,
                    262:                           0,
                    263:                           &cColors,
                    264:                           NULL))
                    265:     {
                    266:         RIP("DISP DrvSetPalette failed DeviceIoControl\n");
                    267:         return(FALSE);
                    268:     }
                    269: 
                    270:     return(TRUE);
                    271: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.