Beispiel #1
0
/////////////////////////////////////////////////////////////////////////////
// CreateWTPalette.
//
// Creates at Windows palette from WT's palette.  First requests WT to read
// it's palette, then gets the entries and populates the RGB table.  Then it
// calls CreateIdentityPalette(), which is a help routine in winpal.cpp
// (provided generously by Microsoft, in the WinG sample PALANIM sample.c).
//
void CreateWTPalette(void)
{
	int i;
	int nColors;
	int r,g,b;
	pal syspal;
   HDC Screen;

   nColors = wt_load_palette();

   for (i=0; i<256; i++) {
		ColorTable[i].rgbRed = 0;
      ColorTable[i].rgbGreen = 0;
      ColorTable[i].rgbBlue = 0;
		ColorTable[i].rgbReserved = 0;
	}

			//WT only has 192 colors, at the moment.  Let's populate our table's
			//upper colors with the System colors, so perhaps WT won't be so
			//self-centered with colors - makes little difference, but I 
			//thought it best to have some colors, peferrably something visible,
			//in the unused palette slots.  This way a bug might be found.
			
   Screen = GetDC(0);
   GetSystemPaletteEntries(Screen,0,10,syspal.aEntries);
   GetSystemPaletteEntries(Screen,246,10,syspal.aEntries + 246);
	ReleaseDC(0,Screen);

			//put system last 10 colors in our last 10 slots, and first 10
			//in second-to-last 10 slots.
   for (i=0; i<10; i++) {
		ColorTable[246+i].rgbRed   = syspal.aEntries[246+i].peRed;
		ColorTable[246+i].rgbGreen = syspal.aEntries[246+i].peGreen;
		ColorTable[246+i].rgbBlue  = syspal.aEntries[246+i].peBlue;

		ColorTable[236+i].rgbRed   = syspal.aEntries[i].peRed;
		ColorTable[236+i].rgbGreen = syspal.aEntries[i].peGreen;
		ColorTable[236+i].rgbBlue  = syspal.aEntries[i].peBlue;
	}

   for (i=0; i<nColors; i++) {
		wt_get_palette_entry(i,&r,&g,&b);
		ColorTable[i].rgbRed = r;
      ColorTable[i].rgbGreen = g;
      ColorTable[i].rgbBlue = b;
		ColorTable[i].rgbReserved = 0;
	}

	if (hpalApp)
		DeleteObject(hpalApp);
	hpalApp = CreateIdentityPalette(ColorTable, nColors);
}
Beispiel #2
0
// Create a GDI palette from a DIB color table
//************************************************************************
HPALETTE CDib::CreatePalette()
//************************************************************************
{
// create an identity palette from the DIB's color table
return ( CreateIdentityPalette( GetColors(), GetNumColors() ) );
}
Beispiel #3
0
//==============================================================================================
// FUNCTION: Resize.
// PURPOSE:  Sizes/Resizes the bitmap to the dimensions given.
//
void CDisplaySurface::Resize(LPCRECT prDisplay)
{
   MEMBERASSERT();
   ASSERT(m_hdcBM);
   WPTRASSERT(prDisplay);

   int nPaletteSize  = m_nPaletteSize;
   int nBitsPerPixel = m_nBitsPerPixel;
   if (m_bMatchScreen)
   {
      ASSERT(m_hdcWin);
      nPaletteSize  = GetDeviceCaps(m_hdcWin, SIZEPALETTE);
      nBitsPerPixel = GetDeviceCaps(m_hdcWin, BITSPIXEL);
   }

   // If nothing has changed, just get out.
   if (m_rDisplay.EqualRect(prDisplay) && 
       (nPaletteSize  == m_nPaletteSize) &&
       (nBitsPerPixel == m_nBitsPerPixel))
      return;

   HDC hDC = Lock();

   // Save the new surface properties.
   m_nPaletteSize  = nPaletteSize;
   m_nBitsPerPixel = nBitsPerPixel;
   m_rDisplay      = *prDisplay;

   // If a DIB was created previously, delete it.
   FreeBitmap();

   int nWidth = m_rDisplay.Width();
   nWidth = max(nWidth, 1);

   int nHeight = m_rDisplay.Height();
   nHeight = max(nHeight, 1);

   // Match the screen color depth.
   UINT uDIBWidthBits  = nWidth * nBitsPerPixel;
   UINT uDIBWidthBytes = ((uDIBWidthBits + 31) & (~31)) >> 3;
   m_ActualSize.cx     = uDIBWidthBytes;
   m_ActualSize.cy     = nHeight;

   if (m_bInverted)
      nHeight = -nHeight;
   
   // add the storage for the DIB colors, if we have any!
   // m_nPaletteSize will be 256 for an 8 bit DIB, and 0 for all other DIBs
   int nBytes = sizeof(BITMAPINFOHEADER) + m_nPaletteSize * sizeof(RGBQUAD);
         
   ASSERT(m_pBitmapInfo==NULL);
   m_pBitmapInfo = (BITMAPINFO *)malloc(nBytes);
   memset(m_pBitmapInfo, 0, nBytes);
   
   // if we've run out of memory, get out of here
   if (!m_pBitmapInfo)
      return;
     
   // set up the information that we need
   BITMAPINFOHEADER *pBitmapInfoHeader = &(m_pBitmapInfo->bmiHeader);

   pBitmapInfoHeader->biSize          = sizeof(BITMAPINFOHEADER); // always this
   pBitmapInfoHeader->biWidth         = nWidth;                   // the width of the bitmap
   pBitmapInfoHeader->biHeight        = nHeight;                  // the height, but negative so we display it upside down
   pBitmapInfoHeader->biPlanes        = 1;                        // Always 1
   pBitmapInfoHeader->biBitCount      = WORD(m_nBitsPerPixel);    // BPP for DIB
   pBitmapInfoHeader->biCompression   = BI_RGB;                   // no compression
   pBitmapInfoHeader->biSizeImage     = 0;                        // Calculation not needed for BI_RGB
   pBitmapInfoHeader->biXPelsPerMeter = 0;                        // These are arbitrary   
   pBitmapInfoHeader->biYPelsPerMeter = 0;                        // These are arbitrary   
   pBitmapInfoHeader->biClrUsed       = m_nPaletteSize;           // Use biBitCount to determine colors used
   pBitmapInfoHeader->biClrImportant  = 0;                        // All colors important, set to 0
   
   m_Palette.DeleteObject();
   if (m_nPaletteSize > 0)
   {
#ifdef _MFC_VER
      m_Palette.CreateHalftonePalette( CDC::FromHandle(m_hdcWin) );
#else
      m_Palette.CreateHalftonePalette(m_hdcWin);
#endif

      ASSERT(m_nPaletteSize <= 256);
      PALETTEENTRY PalEntries[256]         = { 0 };
      PALETTEENTRY IdentityPalEntries[256] = { 0 };

      // fill them in
      int nEntries = m_Palette.GetPaletteEntries(0, m_nPaletteSize, PalEntries);
      LPPALETTEENTRY pPalEntries = PalEntries;

      CreateIdentityPalette(PalEntries, IdentityPalEntries, nEntries);
      pPalEntries = IdentityPalEntries;

      // now convert to DIB color
      RGBQUAD *pDIBColorTable = m_pBitmapInfo->bmiColors;
      for (int i = 0; i < m_nPaletteSize; i++)    
      {
         pDIBColorTable[i].rgbBlue     = pPalEntries[i].peBlue;
         pDIBColorTable[i].rgbGreen    = pPalEntries[i].peGreen;
         pDIBColorTable[i].rgbRed      = pPalEntries[i].peRed;
         pDIBColorTable[i].rgbReserved = 0;
      }
   }

   // Create the DIB section.
   m_hBitmap = CreateDIBSection( hDC, m_pBitmapInfo, DIB_RGB_COLORS, (LPVOID *)(&m_pDibBits), NULL, 0);
   ASSERT(m_hBitmap);

   m_hbmSave = SelectBitmap( hDC, m_hBitmap );
   SetViewportOrgEx( hDC, -m_rDisplay.left, -m_rDisplay.top, NULL);

   Clear( &m_rDisplay );
   Unlock();
}