/* Exported for the windows message loop only */ static void DIB_GrabStaticColors(HWND window) { #ifdef SYSPAL_NOSTATIC HDC hdc; hdc = GetDC(window); SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC256); if ( GetSystemPaletteUse(hdc) != SYSPAL_NOSTATIC256 ) { SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC); } ReleaseDC(window, hdc); #endif }
void AppActivate(BOOL fActive) /**************************************************************************** * * Function: AppActivate * Parameters: fActive - True if app is activating * * Description: If the application is activating, then swap the system * into SYSPAL_NOSTATIC mode so that our palettes will display * correctly. * ****************************************************************************/ { HDC hdc = GetDC(NULL); if (fActive && (GetSystemPaletteUse(hdc) == SYSPAL_STATIC)) { /* Switch to SYSPAL_NOSTATIC */ SetSystemPaletteUse(hdc, SYSPAL_NOSTATIC); } else if (!fActive) { /* Always switch back to SYSPAL_STATIC */ SetSystemPaletteUse(hdc, SYSPAL_STATIC); } ReleaseDC(NULL,hdc); }
//=============================================================================================== // FUNCTION: CreateIdentityPalette // PURPOSE: Fills on output in pRGBIdentityOut with the identity based palette based on the RGB // values passed into this function. The colors given should be in order of importance, // since the RGB colors at the end of the list will probably not be included in the // creation of the palette, since 20 static colors need to be preserved. // If there is no system palette, the function fails. // PARAMETERS: // pRGBEntryIn The array of RGB values to be used to make an identity palette // pRGBIdentityOut Pointer to PALETTEENTRYs. This array is filled with an // identity system palette. Number of elements must be the // same as lNumRGBEntriesIn // lNumRGBEntriesIn Number of elements in pRGBEntryIn // void CDisplaySurface::CreateIdentityPalette(const LPPALETTEENTRY pRGBEntryIn, LPPALETTEENTRY pRGBIdentityOut, int nNumEntries) { // make sure the # of RGB entries is at least as big as the size we're going to create RARRAYASSERT(pRGBEntryIn, nNumEntries); WARRAYASSERT(pRGBIdentityOut, nNumEntries); // get size of system palette, 256 for 8 bit display // if we are greater than 8 bits per pixel, we don't have a palette at all // m_nPaletteSize will be 0 for screen depths > 8 ASSERT(m_nPaletteSize > 0); // make sure we are in 8 bit display // get the system palette entries, since we need to make an identity palette GetSystemPaletteEntries(m_hdcWin, 0, m_nPaletteSize, pRGBIdentityOut); // Get number of static colors and read entire system palette // If the system has no static palette colors just copy everything // the number of static colors in the first half (lower section) of the palette are // the number of static colors divided by 2, since the second half of the // static colors are located at the top (upper) section of the palette int nStaticColors = 0; if (GetSystemPaletteUse(m_hdcWin) == SYSPAL_NOSTATIC) nStaticColors = 0; else nStaticColors = max(GetDeviceCaps(m_hdcWin, NUMCOLORS) / 2, 0); // The palette goes something like this: // // <--static colors--|------usuable colors-------|--static colors--> // The static colors are usually from 0-9 and from 246-255 and the entries // that we can use are in the range 10-245. So nStaticColors will usually equal 10 // Set low part of static entry palette flags to zero for (int i=0; i < nStaticColors; i++) pRGBIdentityOut[i].peFlags = 0; // Now copy over the available part of the system palette // we need to find where the last usable color slot in the palette // is, this is usually at 256-nStaticColors-1=245 (256-10-1=245) slot, // that is the palette size minus half of the static colors // (since half of them reside in the upper half of the palette) // so nFirstUpperStaticColor = 256-10 = 246 int nFirstUpperStaticColor = m_nPaletteSize-nStaticColors; // we've dealt with the first section of the palette // so now we can look at the entries that we will fill up with the given // RGB colors (from 10-245) int nColorIndex=0; for (i=nStaticColors; i < nFirstUpperStaticColor && nColorIndex < nNumEntries; i++, nColorIndex++) { BYTE nFlag = PC_NOCOLLAPSE; pRGBIdentityOut[i] = pRGBEntryIn[nColorIndex]; // we need to look at the upper static colors (upper 10) to see if this color happens // to be a duplicate of one of these, if it is, we need to set this entry as PC_RESERVED // so that we don't allow Windows to match the upper 10 matching color to this color later // if it is not a duplicate, we simply mark it as PC_NOCOLLAPSE so Windows doesn't match // this color to another color in the palette for (int n = nFirstUpperStaticColor; n < m_nPaletteSize; n++) { if (pRGBIdentityOut[n].peRed == pRGBEntryIn[nColorIndex].peRed && pRGBIdentityOut[n].peGreen == pRGBEntryIn[nColorIndex].peGreen && pRGBIdentityOut[n].peBlue == pRGBEntryIn[nColorIndex].peBlue) { nFlag = PC_RESERVED; break; } } pRGBIdentityOut[i].peFlags = nFlag; } // Finish by setting botton part of static entry's palette flags // Set the peFlags of the upper static colors to zero, to match it normally for (; i < m_nPaletteSize; i++) pRGBIdentityOut[i].peFlags = 0; }
int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) { #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400) HDC hdc, mdc; RGBQUAD *pal; #else HDC hdc; #endif int i; int moved_entries = 0; /* Update the display palette */ hdc = GetDC(SDL_Window); if ( screen_pal ) { PALETTEENTRY *entry; for ( i=0; i<ncolors; ++i ) { entry = &screen_logpal->palPalEntry[firstcolor+i]; entry->peRed = colors[i].r; entry->peGreen = colors[i].g; entry->peBlue = colors[i].b; entry->peFlags = PC_NOCOLLAPSE; } #ifdef SYSPAL_NOSTATIC /* Check to make sure black and white are in position */ if ( GetSystemPaletteUse(hdc) != SYSPAL_NOSTATIC256 ) { moved_entries += CheckPaletteEntry(screen_logpal, 0, 0x00, 0x00, 0x00); moved_entries += CheckPaletteEntry(screen_logpal, screen_logpal->palNumEntries-1, 0xff, 0xff, 0xff); } /* FIXME: If we don't have full access to the palette, what we really want to do is find the 236 most diverse colors in the desired palette, set those entries (10-245) and then map everything into the new system palette. */ #endif #ifndef _WIN32_WCE /* Copy the entries into the system palette */ UnrealizeObject(screen_pal); #endif SetPaletteEntries(screen_pal, 0, screen_logpal->palNumEntries, screen_logpal->palPalEntry); SelectPalette(hdc, screen_pal, FALSE); RealizePalette(hdc); } #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400) /* Copy palette colors into DIB palette */ pal = SDL_stack_alloc(RGBQUAD, ncolors); for ( i=0; i<ncolors; ++i ) { pal[i].rgbRed = colors[i].r; pal[i].rgbGreen = colors[i].g; pal[i].rgbBlue = colors[i].b; pal[i].rgbReserved = 0; } /* Set the DIB palette and update the display */ mdc = CreateCompatibleDC(hdc); SelectObject(mdc, screen_bmp); SetDIBColorTable(mdc, firstcolor, ncolors, pal); if ( moved_entries || !grab_palette ) { BitBlt(hdc, 0, 0, this->screen->w, this->screen->h, mdc, 0, 0, SRCCOPY); } DeleteDC(mdc); SDL_stack_free(pal); #endif ReleaseDC(SDL_Window, hdc); return(1); }