//********************************************************************************
void Create16ColorsStdPalette (CPalette& pal)
{
	const int nStdColorCount = 20;
	CPalette* pPalDefault = CPalette::FromHandle ((HPALETTE) ::GetStockObject (DEFAULT_PALETTE));
	if (pPalDefault == NULL)
	{
		ASSERT (FALSE);
		return;
	}

	const int nColors = 16;
	UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);
	LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];

	pLP->palVersion = 0x300;
	pLP->palNumEntries = (USHORT) nColors;

	pal.CreatePalette (pLP);

	delete[] pLP;

	PALETTEENTRY palEntry;
	int iDest = 0;

	for (int i = 0; i < nStdColorCount; i++)
	{
		if (i < 8 || i >= 12)
		{
			pPalDefault->GetPaletteEntries (i, 1, &palEntry);
			pal.SetPaletteEntries (iDest++, 1, &palEntry);
		}
	}
}
BOOL CDib::SetPalette( CPalette& palette )
{
	if( IsIndexed() )
	{
		int iColors = 0;
		if (!palette.GetObject(sizeof(iColors), &iColors)) 
		{
			TRACE("Failed to get num palette colors");
			return FALSE;
		}
		
		ASSERT(iColors>= 0 && iColors<=256);
//		iColors = min(iColors, GetColorTableEntries());
		PALETTEENTRY pe[256];
		palette.GetPaletteEntries(0, iColors, pe);

		RGBQUAD quad[256] = {0};
		for (int i = 0; i < iColors; i++) 
		{
			quad[i].rgbRed = pe[i].peRed;    
			quad[i].rgbGreen = pe[i].peGreen;    
			quad[i].rgbBlue = pe[i].peBlue;
		}

		SetColorTable(0, iColors, &(quad[0]));

		//update copy of the palette
		//GetPalette(m_palette);
	}
	

    return TRUE;
}
Example #3
0
static int MergePalette( CDC *pDC, LPRGBQUAD pC, int nColors ) 
{
	WORD	nOldEntries, nNewEntries;
	COLORREF	rgb;
	int	idx, i;

	CPalette*	pPal = pDC->GetCurrentPalette();
	pPal->GetObject( sizeof( nOldEntries ), &nOldEntries );
	LPLOGPALETTE	lp = (LPLOGPALETTE) new BYTE[ sizeof( LOGPALETTE ) + ( nOldEntries + nColors ) * sizeof ( PALETTEENTRY ) ];
	LPPALETTEENTRY	pe = lp->palPalEntry;

	if( pPal->GetPaletteEntries( 0, nOldEntries, pe ) )
		pe += nOldEntries;

	for( i = 0, nNewEntries = 0; i < nColors; i++ ) {
		rgb = RGB(pC->rgbRed,pC->rgbGreen,pC->rgbBlue);
		idx = pPal->GetNearestPaletteIndex( rgb );
		pPal->GetPaletteEntries( idx, 1, pe );
		if( ( pe->peRed != GetRValue( rgb ) )
			|| pe->peGreen != GetGValue( rgb )
			|| pe->peBlue != GetBValue( rgb ) )
		{
			pe->peRed	= GetRValue( rgb );
			pe->peGreen	= GetGValue( rgb );
			pe->peBlue	= GetBValue( rgb );
			pe->peFlags	= NULL;
			pe++;
			nNewEntries++;
		}
		pC++;
	}
	if( nNewEntries > 0 ) {
		lp->palVersion = PALVERSION;
		lp->palNumEntries = nOldEntries + nNewEntries;
		CPalette	pal, *pOldPal;
		pal.CreatePalette( lp );
		pOldPal = pDC->SelectPalette( &pal, FALSE );
		pDC->RealizePalette();
	}
	delete lp;
	return (int) nNewEntries;
}
void CDib::GetSelectionIndex(COLORREF crColor, UtilWin::CIntArray& selectionArray)
{
	selectionArray.RemoveAll();
	
	CPalette palette;
	GetPalette(palette);
	int nbColor = palette.GetEntryCount();
	ASSERT(nbColor >= 0 && nbColor <=256);

	PALETTEENTRY pe[256];
	palette.GetPaletteEntries(0, nbColor, pe);

	for(int i=0; i<nbColor;i++)
	{
		if( RGB( pe[i].peRed, pe[i].peGreen, pe[i].peBlue) == crColor)
			selectionArray.Add(i);
	}
}
bool CColorPaletteButton::verifyColor()
{
   CDC* dc = GetDC();

   ASSERT(dc != NULL);
   ASSERT(dc->GetDeviceCaps(RASTERCAPS) & RC_BITBLT);

   CRect clientRect;
   GetClientRect(&clientRect);
   CPoint center((clientRect.left + clientRect.right)/2,(clientRect.top + clientRect.bottom)/2);

   COLORREF colorButtonColor = dc->GetPixel(center);

   m_appPalette.pushPalette(dc);

   PALETTEENTRY paletteEntry;
   CPalette* palette = dc->GetCurrentPalette();
   ASSERT(palette != NULL);
   int numEntries = palette->GetEntryCount();

   VERIFY(palette->GetPaletteEntries(m_appPalette.getEditIndex(),1,&paletteEntry) > 0);

   COLORREF paletteColor = RGB(paletteEntry.peRed,paletteEntry.peGreen,paletteEntry.peBlue);

   bool retval = (colorButtonColor == paletteColor);

   m_appPalette.popPalette(dc);

   if (!retval)
   {
      TRACE("CColorPaletteButton::verifyColor() - %s, buttonColor=0x%08x, paletteColor=0x%08x, \n",
         retval ? "success" : "failure",colorButtonColor,paletteColor);
   }
   else
   {
      TRACE("CColorPaletteButton::verifyColor() - %s, buttonColor=0x%08x, paletteColor=0x%08x, \n",
         retval ? "success" : "failure",colorButtonColor,paletteColor);
   }

   return retval;
}
Example #6
0
void CGelDoc::OnGelHueRight() 
{
	CPalette* pPal = AfxGetPaletteApp()->GetAppPalette();
	if (!pPal)
		return;

	int i;
	for (i = 0; i < 256; i++)
	{
		if (m_abySelection[i])
		{
			PALETTEENTRY entry;
			BYTE k;
			pPal->GetPaletteEntries(i, 1, &entry);
			k = pPal->GetNearestPaletteIndex(
				RGB(entry.peBlue, entry.peRed, entry.peGreen));
			m_abyTransform[i] = k;
		}
	}

	SetModifiedFlag();
	ApplyGel();
}