Example #1
0
Bool
winCreateColormapShadowGDI (ColormapPtr pColormap)
{
    LPLOGPALETTE		lpPaletteNew = NULL;
    DWORD			dwEntriesMax;
    VisualPtr		pVisual;
    HPALETTE		hpalNew = NULL;
    winCmapPriv(pColormap);

    /* Get a pointer to the visual that the colormap belongs to */
    pVisual = pColormap->pVisual;

    /* Get the maximum number of palette entries for this visual */
    dwEntriesMax = pVisual->ColormapEntries;

    /* Allocate a Windows logical color palette with max entries */
    lpPaletteNew = malloc (sizeof (LOGPALETTE)
                           + (dwEntriesMax - 1) * sizeof (PALETTEENTRY));
    if (lpPaletteNew == NULL)
    {
        ErrorF ("winCreateColormapShadowGDI - Couldn't allocate palette "
                "with %d entries\n",
                dwEntriesMax);
        return FALSE;
    }

    /* Zero out the colormap */
    ZeroMemory (lpPaletteNew, sizeof (LOGPALETTE)
                + (dwEntriesMax - 1) * sizeof (PALETTEENTRY));

    /* Set the logical palette structure */
    lpPaletteNew->palVersion = 0x0300;
    lpPaletteNew->palNumEntries = dwEntriesMax;

    /* Tell Windows to create the palette */
    hpalNew = CreatePalette (lpPaletteNew);
    if (hpalNew == NULL)
    {
        ErrorF ("winCreateColormapShadowGDI - CreatePalette () failed\n");
        free (lpPaletteNew);
        return FALSE;
    }

    /* Save the Windows logical palette handle in the X colormaps' privates */
    pCmapPriv->hPalette = hpalNew;

    /* Free the palette initialization memory */
    free (lpPaletteNew);

    return TRUE;
}
Example #2
0
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner):TForm(Owner)
{
  char *ptr;
  char aux[100];
  S1 = new CSocket();
  wsprintf(aux, "     %s  %s", S1->NombreHostLocal, S1->cadenaIP);
  PHOST->Caption = aux;

  LeyendoFoto = false;

  PBinin->Caption = (int)Binin;
  TBBinin->Position = (int)Binin;

  NumeroFilas = PFilas->Caption.ToInt() / Binin;
  NumeroColumnas = PColumnas->Caption.ToInt() / Binin;
  PB1->Width = NumeroColumnas + 4;
  PB1->Height = NumeroFilas + 4;
  X1F = X1 = PX1->Caption.ToInt();
  X2F = X2 = PX2->Caption.ToInt();
  Y1F = Y1 = PY1->Caption.ToInt();
  Y2F = Y2 = PY2->Caption.ToInt();
  SysPal.lpal.palVersion = 0x300;
  SysPal.lpal.palNumEntries = 256;
  for(int c = 0; c < 256; c++)
  {
    SysPal.dummy[c].peRed = c;
    SysPal.dummy[c].peGreen = c;
    SysPal.dummy[c].peBlue = c;
    SysPal.dummy[c].peFlags = PC_NOCOLLAPSE;
  }

  BM1 = new Graphics::TBitmap();
  BM1->Height = NumeroFilas;
  BM1->Width = NumeroColumnas;
  BM1->PixelFormat = pf8bit;
  BM1->Palette = CreatePalette(&SysPal.lpal);

  Filtro = new CRueda(PFiltro, 0, 0, 130, 7, "Filtro", 'z');
  //PFiltro->Left = 20;
  PFiltro->Width = Filtro->Width;
  PFiltro->Height = Filtro->Height;
  Filtro->S1 = S1;
  Filtro->enviarReset();

  Shuter = new CRueda(PShuter, 0, 0, 130, 3, "Shuter", 'y');
  //PShuter->Left = 20;
  PShuter->Width = Shuter->Width;
  PShuter->Height = Shuter->Height;
  Shuter->S1 = S1;
  Shuter->enviarReset();
}
Example #3
0
void CHyperLink::Initialize() 
{
	m_lpLinkText = NULL;
	m_lpLinkUrl  = NULL;

	m_hFont.CreateFont(14,0,0,0,FW_NORMAL,0,0,0,
		ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
		ANTIALIASED_QUALITY,DEFAULT_PITCH | FF_DONTCARE,"Arial");

	m_bUnderlineAlways = FALSE;
	m_bIsLink          = TRUE;
	m_bLockInPosition  = FALSE;
	m_bMultiline       = FALSE;

	m_crLinkUp     = RGB(0,66,118);
	m_crLinkHover  = RGB(255,0,0);
	m_crLinkDown   = RGB(200,0,225);
	m_crBackGround = ::GetSysColor(COLOR_BTNFACE);

	m_crBorder     = RGB(0,0,0);
	m_nBorderSize  = 0;
	m_nBorderStyle = PS_SOLID;

	m_hReg  = NULL;
	m_hHand = ::LoadCursor(NULL, MAKEINTRESOURCE(32649));

	m_hIconUp		= NULL;
	m_hIconHover	= NULL;
	m_hIconDown		= NULL;
	m_hIconDisabled = NULL;
	m_uShowIcon		= SI_ICONUP_ON		 | SI_ICONUP_LEFT		|   //Default: icons on the left Up/Hover/Down/Disabled
					  SI_ICONHOVER_ON	 | SI_ICONHOVER_LEFT	| 
					  SI_ICONDOWN_ON	 | SI_ICONDOWN_LEFT     |
					  SI_ICONDISABLED_ON | SI_ICONDISABLED_LEFT;

	m_bAutoGenerateDisabled = FALSE;
	m_bAutoGenerated        = FALSE;

	m_pToolTip			= &m_ToolTip;

	//Status and Mouse control variables
	m_bDisabled  = FALSE;

	m_bMouseIn   = FALSE;
	m_bMouseDown = FALSE;

	m_bMovingWindow = FALSE;

	CreatePalette();
}
Example #4
0
/////////////////////////////////////////////////////////////////////////////
//
// Attach is just like the CGdiObject version, except it also creates the
// palette.
//
/////////////////////////////////////////////////////////////////////////////
zBOOL
ZDib::Attach( HGDIOBJ hbm )
{
   if ( CBitmap::Attach( hbm ) )
   {
      if ( GetBitmap( &m_bitmap ) == 0 )     // load BITMAP for speed
         return( FALSE );

      m_palette.DeleteObject( );             // in case one is already there
      return( CreatePalette( m_palette ) );  // create palette
   }

   return( FALSE );
}
Example #5
0
HPALETTE
image_make_bitmap_palette( Handle img)
{
   PDrawable i    = ( PDrawable) img;
   int j, nColors = i-> palSize;
   XLOGPALETTE lp;
   HPALETTE r;
   RGBColor  dest[ 256];
   PRGBColor logp = i-> palette;

   lp. palVersion = 0x300;
   lp. palNumEntries = nColors;

   if ( nColors == 0) return nil;

   if ( !dsys(img)p256) {
      if ( nColors > 256) {
         dsys(img)p256 = ( PXLOGPALETTE) malloc( sizeof( XLOGPALETTE));
         cm_squeeze_palette( i-> palette, nColors, dest, 256);
         nColors = lp. palNumEntries = 256;
         logp = dest;
      }

      for ( j = 0; j < nColors; j++) {
         lp. palPalEntry[ j]. peRed    = logp[ j]. r;
         lp. palPalEntry[ j]. peGreen  = logp[ j]. g;
         lp. palPalEntry[ j]. peBlue   = logp[ j]. b;
         lp. palPalEntry[ j]. peFlags  = 0;
      }

      if ( dsys(img)p256) memcpy( dsys(img)p256, &lp, sizeof( XLOGPALETTE));
      if ( !( r = CreatePalette(( LOGPALETTE*) &lp))) apiErrRet;
   } else {
      if ( !( r = CreatePalette(( LOGPALETTE*) dsys(img)p256))) apiErrRet;
   }
   return r;
}
Example #6
0
/* Primitive palette functions */
static int set_palette (UINT8 *pal, int scol, int numcols)
{
	int i;

#if 0
	HDC hdc;
	LOGPALETTE *palette;
	PALETTEENTRY *entries;

	hdc = GetDC(hwndMain);

	if (GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL) <= 8) {
		entries = (PALETTEENTRY *)malloc(32 * sizeof(PALETTEENTRY));

		for (i = scol; i < numcols; i++) {
			entries[i].peRed   = pal[i*3    ] << 2;
			entries[i].peGreen = pal[i*3 + 1] << 2;
			entries[i].peBlue  = pal[i*3 + 2] << 2;
			entries[i].peFlags = PC_NOCOLLAPSE;
		}

		palette = malloc(sizeof(*palette) + 32 * sizeof(PALETTEENTRY));
		if (palette == NULL) {
			OutputDebugString("malloc failed for palette");
			return err_Unk;
		}
		palette->palVersion = 0x300;
		palette->palNumEntries = 32;
		g_hPalette = CreatePalette(palette);
		free(palette);

		SetPaletteEntries(g_hPalette, 0, 32, entries);
		SelectPalette(hdc, g_hPalette, FALSE);
		RealizePalette(hdc);
	} else
#endif

	for (i = scol; i < numcols; i ++) {
		g_screen.binfo->bmiColors[i].rgbRed  = (pal[i*3    ]) << 2;
		g_screen.binfo->bmiColors[i].rgbGreen= (pal[i*3 + 1]) << 2;
		g_screen.binfo->bmiColors[i].rgbBlue = (pal[i*3 + 2]) << 2;
		g_screen.binfo->bmiColors[i].rgbReserved = 0;
	}


	ReleaseDC(hwndMain, hdc);

	return err_OK;
}
Example #7
0
HPALETTE FAR CJpegFile::GetSystemPalette(void)
{
	HDC hDC;                // handle to a DC
	static HPALETTE hPal = NULL;   // handle to a palette
	HANDLE hLogPal;         // handle to a logical palette
	LPLOGPALETTE lpLogPal;  // pointer to a logical palette
	int nColors;            // number of colors
	
	/* Find out how many palette entries we want. */
	
	hDC = GetDC(NULL);
	if (!hDC)
		return NULL;
	nColors = PalEntriesOnDevice(hDC);   // Number of palette entries
	if(nColors == 0) return NULL;
	
	/* Allocate room for the palette and lock it. */
	hLogPal = GlobalAlloc(GHND, sizeof(LOGPALETTE) + nColors * sizeof(
		PALETTEENTRY));
	
	/* if we didn't get a logical palette, return NULL */
	if (!hLogPal)
		return NULL;
	
	/* get a pointer to the logical palette */
	lpLogPal = (LPLOGPALETTE)GlobalLock(hLogPal);
	
	/* set some important fields */
	lpLogPal->palVersion = PALVERSION;
	lpLogPal->palNumEntries = nColors;
	
	/* Copy the current system palette into our logical palette */
	
	GetSystemPaletteEntries(hDC, 0, nColors, 
		(LPPALETTEENTRY)(lpLogPal->palPalEntry));
	
	/*  Go ahead and create the palette.  Once it's created,
	 *  we no longer need the LOGPALETTE, so free it.
     */
	
	hPal = CreatePalette(lpLogPal);
	
	/* clean up */
	GlobalUnlock(hLogPal);
	GlobalFree(hLogPal);
	ReleaseDC(NULL, hDC);
	
	return hPal;
}
Example #8
0
/*
 * Given a BITMAPINFOHEADER, create a palette based on the color table.
 *
 * Returns the handle of a palette, or zero if something went wrong.
 */
static HPALETTE PASCAL NEAR MakeDIBPalette(LPBITMAPINFOHEADER lpInfo)
{
    PLOGPALETTE npPal;
    RGBQUAD FAR *lpRGB;
    HPALETTE hLogPal;
    DWORD i;

    /*
     * since biClrUsed field was filled during the loading of the DIB,
     * we know it contains the number of colors in the color table.
     */
    if (lpInfo->biClrUsed)
    {
        npPal = (PLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) +
                                        (WORD)lpInfo->biClrUsed * sizeof(PALETTEENTRY));
        if (!npPal)
            return (FALSE);

        npPal->palVersion = 0x300;
        npPal->palNumEntries = (WORD)lpInfo->biClrUsed;

        /* get pointer to the color table */
        lpRGB = (RGBQUAD FAR *)((LPSTR)lpInfo + lpInfo->biSize);

        /* copy colors from the color table to the LogPalette structure */
        for (i = 0; i < lpInfo->biClrUsed; i++, lpRGB++)
        {
            npPal->palPalEntry[i].peRed = lpRGB->rgbRed;
            npPal->palPalEntry[i].peGreen = lpRGB->rgbGreen;
            npPal->palPalEntry[i].peBlue = lpRGB->rgbBlue;
            npPal->palPalEntry[i].peFlags = PC_NOCOLLAPSE;
        }

        hLogPal = CreatePalette((LPLOGPALETTE)npPal);
        LocalFree((HANDLE)npPal);
        return (hLogPal);
    }

    /*
     * 24-bit DIB with no color table.  return default palette.  Another
     * option would be to create a 256 color "rainbow" palette to provide
     * some good color choices.
     */
    else
    {
        return (GetStockObject(DEFAULT_PALETTE));
    }
}
Example #9
0
HPALETTE CreateRoutine (HWND hwnd)
{
     HPALETTE hPalette ;
     
     lp.palVersion             = 0x0300 ;
     lp.palNumEntries          = 1 ;
     lp.palPalEntry[0].peRed   = 255 ;
     lp.palPalEntry[0].peGreen = 255 ;
     lp.palPalEntry[0].peBlue  = 255 ;
     lp.palPalEntry[0].peFlags = PC_RESERVED ;
   
     hPalette = CreatePalette (&lp) ;
     
     SetTimer (hwnd, ID_TIMER, 50, NULL) ;
     return hPalette ;
}
Example #10
0
HPALETTE GetSystemPalette(void)
{
   HDC hDC;                // handle to a DC
   HPALETTE hPal = NULL;   // handle to a palette
   HANDLE hLogPal;         // handle to a logical palette
   LPLOGPALETTE lpLogPal;  // pointer to a logical palette
   int i, nColors;         // loop index, number of colors

   /* Find out how many palette entries we want. */

   hDC = GetDC(NULL);
   if (!hDC)
      return NULL;
   nColors = PalEntriesOnDevice(hDC);
   ReleaseDC(NULL, hDC);

   /* Allocate room for the palette and lock it. */
   hLogPal = GlobalAlloc(GHND, sizeof(LOGPALETTE) + nColors * sizeof(
                         PALETTEENTRY));

   /* if we didn't get a logical palette, return NULL */
   if (!hLogPal)
      return NULL;

   /* get a pointer to the logical palette */
   lpLogPal = (LPLOGPALETTE)GlobalLock(hLogPal);

   /* set some important fields */
   lpLogPal->palVersion = PALVERSION;
   lpLogPal->palNumEntries = nColors;
   for (i = 0; i < nColors; i++)
   {
      lpLogPal->palPalEntry[i].peBlue = 0;
      *((LPWORD)(&lpLogPal->palPalEntry[i].peRed)) = i;
      lpLogPal->palPalEntry[i].peFlags = PC_EXPLICIT;
   }

   /*  Go ahead and create the palette.  Once it's created,
    *  we no longer need the LOGPALETTE, so free it.
    */
   hPal = CreatePalette(lpLogPal);

   /* clean up */
   GlobalUnlock(hLogPal);
   GlobalFree(hLogPal);
   return hPal;
}
Example #11
0
void
setupPalette(HDC hDC)
{
    int pixelFormat = GetPixelFormat(hDC);
    PIXELFORMATDESCRIPTOR pfd;
    LOGPALETTE* pPal;
    int paletteSize;

    DescribePixelFormat(hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

    if (pfd.dwFlags & PFD_NEED_PALETTE) {
	paletteSize = 1 << pfd.cColorBits;
    } else {
	return;
    }

    pPal = (LOGPALETTE*)
	malloc(sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
    pPal->palVersion = 0x300;
    pPal->palNumEntries = paletteSize;

    /* build a simple RGB color palette */
    {
	int redMask = (1 << pfd.cRedBits) - 1;
	int greenMask = (1 << pfd.cGreenBits) - 1;
	int blueMask = (1 << pfd.cBlueBits) - 1;
	int i;

	for (i=0; i<paletteSize; ++i) {
	    pPal->palPalEntry[i].peRed =
		    (((i >> pfd.cRedShift) & redMask) * 255) / redMask;
	    pPal->palPalEntry[i].peGreen =
		    (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask;
	    pPal->palPalEntry[i].peBlue =
		    (((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask;
	    pPal->palPalEntry[i].peFlags = 0;
	}
    }

    hPalette = CreatePalette(pPal);
    free(pPal);

    if (hPalette) {
	SelectPalette(hDC, hPalette, FALSE);
	RealizePalette(hDC);
    }
}
BOOL createRGBPalette(HDC hDC)
{
  
   PIXELFORMATDESCRIPTOR pfd;
   LOGPALETTE* pPal;
   HPALETTE hPal;
   int i,j,n;

   /* Check to see if we need a palette */
   n = GetPixelFormat(hDC);
   DescribePixelFormat(hDC, n, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
   if (!(pfd.dwFlags & PFD_NEED_PALETTE)) return FALSE ; 

   /* Allocate a log pal and fill it with the color table info */
   pPal = (LOGPALETTE*) malloc(sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY));
   pPal->palVersion = 0x300; /* Windows 3.0 */
   pPal->palNumEntries = 256; /* table size */

   /*/ Create palette */
   n = 1 << pfd.cColorBits;
   for (i=0; i<n; i++)
   {
      pPal->palPalEntry[i].peRed =
	     ComponentFromIndex(i, pfd.cRedBits, pfd.cRedShift);
      pPal->palPalEntry[i].peGreen =
	     ComponentFromIndex(i, pfd.cGreenBits, pfd.cGreenShift);
      pPal->palPalEntry[i].peBlue =
	     ComponentFromIndex(i, pfd.cBlueBits, pfd.cBlueShift);
      pPal->palPalEntry[i].peFlags = 0;
   }

   if ((pfd.cColorBits == 8)			       &&
       (pfd.cRedBits   == 3) && (pfd.cRedShift	 == 0) &&
       (pfd.cGreenBits == 3) && (pfd.cGreenShift == 3) &&
       (pfd.cBlueBits  == 2) && (pfd.cBlueShift	 == 6))
   {
      for (j = 1 ; j <= 12 ; j++)
	  pPal->palPalEntry[m_defaultOverride[j]] = m_defaultPalEntry[j];
   }


   hPal = CreatePalette(pPal);
   SelectPalette(hDC,hPal,FALSE);
   

   return TRUE;
}
Example #13
0
static HPALETTE CreateCIPalette( HDC Dc )
{
    LOGPALETTE *LogicalPalette;
    HPALETTE StockPalette;
    UINT PaletteSize, StockPaletteSize, EntriesToCopy;

    if ( (Dc != NULL) && (NULL == tkhpalette) )
    {
                PaletteSize = 256; //(Pfd.cColorBits >= 8) ? 256 : (1 << Pfd.cColorBits);

                LogicalPalette = AllocateZeroedMemory( sizeof(LOGPALETTE) +
                                        (PaletteSize * sizeof(PALETTEENTRY)) );

                if ( NULL != LogicalPalette )
                {
                    LogicalPalette->palVersion    = 0x300;
                    LogicalPalette->palNumEntries = PaletteSize;

                    StockPalette     = GetStockObject(DEFAULT_PALETTE);
                    StockPaletteSize = GetPaletteEntries( StockPalette, 0, 0, NULL );

                    /*
                     *  start by copying default palette into new one
                     */

                    EntriesToCopy = StockPaletteSize < PaletteSize ?
                                        StockPaletteSize : PaletteSize;

                    GetPaletteEntries( StockPalette, 0, EntriesToCopy,
                                        LogicalPalette->palPalEntry );

                    /*
                     *  If we are taking possession of the system colors,
                     *  must guarantee that 0 and 255 are black and white
                     *  (respectively).
                     */

                    tkhpalette = CreatePalette(LogicalPalette);

                    FreeMemory(LogicalPalette);

                    RealizePaletteNow( Dc, tkhpalette);
                }
            }
    return( tkhpalette );
}
Example #14
0
void QGLWidget::setColormap(const QGLColormap & c)
{
    Q_D(QGLWidget);
    d->cmap = c;

    if (d->cmap.handle()) { // already have an allocated cmap
        d->updateColormap();
    } else {
        LOGPALETTE *lpal = (LOGPALETTE *) malloc(sizeof(LOGPALETTE)
                                                 +c.size()*sizeof(PALETTEENTRY));
        lpal->palVersion    = 0x300;
        lpal->palNumEntries = c.size();
        d->cmap.setHandle(CreatePalette(lpal));
        free(lpal);
        d->updateColormap();
    }
}
	void OGLWindow::setupPalette()
	{
		int pixelFormat = GetPixelFormat(hDC ());
		PIXELFORMATDESCRIPTOR pfd;
		LOGPALETTE* pPal;
		int paletteSize;

		int redMask, greenMask, blueMask;
		int i;

		DescribePixelFormat(hDC (), pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

		if (pfd.dwFlags & PFD_NEED_PALETTE)
			paletteSize = 1 << pfd.cColorBits;
		else
			return;

		pPal = (LOGPALETTE*)LocalAlloc(LPTR, sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
		pPal->palVersion = 0x300;
		pPal->palNumEntries = (short)paletteSize;

		//	build a simple RGB color palette
		redMask   = (1 << pfd.cRedBits)   - 1;
		greenMask = (1 << pfd.cGreenBits) - 1;
		blueMask  = (1 << pfd.cBlueBits)  - 1;

		for (i=0; i<paletteSize; ++i)
		{	pPal->palPalEntry[i].peRed = (BYTE)(
				(((i >> pfd.cRedShift) & redMask) * 255) / redMask);
			pPal->palPalEntry[i].peGreen = (BYTE)(
				(((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask);
			pPal->palPalEntry[i].peBlue = (BYTE)(
				(((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask);
			pPal->palPalEntry[i].peFlags = 0;
		}

		hPalette_ = CreatePalette(pPal);
		LocalFree(pPal);

		if (hPalette_)
		{
			DeleteObject(SelectPalette(hDC (), hPalette_, FALSE));
			RealizePalette(hDC ());
		}
	}
Example #16
0
void __fastcall TForm1::RBK400Click(TObject *Sender)
{
  if(RBK400->Checked == true)
  {
    RBK1600->Checked == false;
    NumeroColumnas = 768;
    NumeroFilas = 512;
  }
  else
  {
    RBK1600->Checked == true;
    NumeroColumnas = 768*2;
    NumeroFilas = 512*2;
  }
  PFilas->Caption = NumeroFilas;
  PColumnas->Caption = NumeroColumnas;
  X1 = Y1 = 0;
  X1F = Y1F = 0;
  X2 = X2F = NumeroColumnas;
  Y2 = Y2F = NumeroFilas;
  PX1->Caption = X1;
  PY1->Caption = Y1;
  PX2->Caption = X2;
  PY2->Caption = Y2;
  PFil->Caption = NumeroFilas;
  PCol->Caption = NumeroColumnas;
  PB1->Width = X2 + 4;
  PB1->Height = Y2 + 4;
  delete BM1;
  BM1 = new Graphics::TBitmap();
  BM1->Height = NumeroFilas;
  BM1->Width = NumeroColumnas;
  BM1->PixelFormat = pf8bit;
  BM1->Palette = CreatePalette(&SysPal.lpal);
  TBBinin->Position = 1;
  for (int y = 0; y < NumeroFilas; y++)
  {
    for (int x = 0; x < NumeroColumnas; x++)
    {
      Foto[y][x] = 0;
    }
  }
  BitBlt(PB1->Canvas->Handle, 0, numeroLineaanterior, BM1->Width, nl - numeroLineaanterior,
         BM1->Canvas->Handle, 0, numeroLineaanterior, SRCCOPY);
}
Example #17
0
VOID vPaintStripes(HDC hdc, RECT *prcl)
{
    LOGPALETTE256 logPal256;
    DWORD ulTemp;
    HBRUSH hBrush, hOldBrush;
    HPALETTE hpalExplicit,hpalTemp;

    logPal256.palVersion    = 0x300;
    logPal256.palNumEntries = 256;

// Set up explicit palette.

    for (ulTemp = 0; ulTemp < 256; ulTemp++)
    {
	logPal256.palPalEntry[ulTemp].peRed	 = ulTemp;
	logPal256.palPalEntry[ulTemp].peGreen	 = 0;
	logPal256.palPalEntry[ulTemp].peBlue	 = 0;
	logPal256.palPalEntry[ulTemp].peFlags	 = PC_EXPLICIT;
    }

    hpalExplicit = CreatePalette((LOGPALETTE *) &logPal256);
    hpalTemp = SelectPalette(hdc,hpalExplicit,0);
    RealizePalette(hdc);

// Paint Surface with all colors.

    for (ulTemp = 0; ulTemp < 256; ulTemp++)
    {
	hBrush = CreateSolidBrush(PALETTEINDEX(ulTemp));
	hOldBrush = SelectObject(hdc,hBrush);

	PatBlt(hdc,
	       (((prcl->right - prcl->left) * ulTemp) / 256),
	       0,
	       (((prcl->right - prcl->left) / 256) + 3) ,
	       (prcl->bottom - prcl->top),
	       PATCOPY);

	SelectObject(hdc, hOldBrush);
	DeleteObject(hBrush);
    }

    SelectPalette(hdc,hpalTemp,0);
    DeleteObject(hpalExplicit);
}
Example #18
0
static void DIB_CreatePalette(_THIS, int bpp)
{

	LOGPALETTE *palette;
	HDC hdc;
	int ncolors;

	ncolors = (1 << bpp);
	palette = (LOGPALETTE *)SDL_malloc(sizeof(*palette)+
				ncolors*sizeof(PALETTEENTRY));
	palette->palVersion = 0x300;
	palette->palNumEntries = ncolors;
	hdc = GetDC(SDL_Window);
	GetSystemPaletteEntries(hdc, 0, ncolors, palette->palPalEntry);
	ReleaseDC(SDL_Window, hdc);
	screen_pal = CreatePalette(palette);
	screen_logpal = palette;
}
Example #19
0
static HPALETTE CreateDefaultPalette()
{
	union
	{
		LOGPALETTE LogPalette;
		PALETTEENTRY pad[sizeof(LOGPALETTE)/sizeof(PALETTEENTRY)
			+ DefaultPaletteSize];
	} u;
	int i;

	/* create logical palette from default palette */
	u.LogPalette.palVersion = 0x0300;
	u.LogPalette.palNumEntries = DefaultPaletteSize;
	for (i = 0; i < DefaultPaletteSize; i++)
		u.LogPalette.palPalEntry[i] = DefaultPalette[i];
	return (CreatePalette(&u.LogPalette));

}
Example #20
0
/***********************************************************************
 *           PALETTE_Init
 *
 * Create the system palette.
 */
HPALETTE PALETTE_Init(void)
{
    HPALETTE          hpalette;
    LOGPALETTE *        palPtr;

    /* create default palette (20 system colors) */

    palPtr = HeapAlloc( GetProcessHeap(), 0,
             sizeof(LOGPALETTE) + (NB_RESERVED_COLORS-1)*sizeof(PALETTEENTRY));
    if (!palPtr) return FALSE;

    palPtr->palVersion = 0x300;
    palPtr->palNumEntries = NB_RESERVED_COLORS;
    memcpy( palPtr->palPalEntry, sys_pal_template, sizeof(sys_pal_template) );
    hpalette = CreatePalette( palPtr );
    HeapFree( GetProcessHeap(), 0, palPtr );
    return hpalette;
}
Example #21
0
HPALETTE CreateSystemPalette(void)
{
	LOGPALETTE * pLogPal = (LOGPALETTE *) new char[sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * 255];

	pLogPal->palVersion    = 0x300;
	pLogPal->palNumEntries = 256;

	HDC hDC = GetDC(NULL);

	GetSystemPaletteEntries(hDC, 0, 256, pLogPal->palPalEntry);
	
	ReleaseDC(NULL, hDC);

	HPALETTE hPal = CreatePalette(pLogPal);
	delete [] (char *) pLogPal;

	return hPal;
}
Example #22
0
HPALETTE CreateAllPurposePalette (void)
{
     HPALETTE hPalette ;
     int          i, incr, R, G, B ;
     LOGPALETTE * plp ;

     plp = malloc (sizeof (LOGPALETTE) + 246 * sizeof (PALETTEENTRY)) ;

     plp->palVersion    = 0x0300 ;
     plp->palNumEntries = 247 ;

          // The following loop calculates 31 gray shades, but 3 of them
          //        will match the standard 20 colors

     for (i = 0, G = 0, incr = 8 ; G <= 0xFF ; i++, G += incr)
     {
          plp->palPalEntry[i].peRed   = (BYTE) G ;
          plp->palPalEntry[i].peGreen = (BYTE) G ;
          plp->palPalEntry[i].peBlue  = (BYTE) G ;
          plp->palPalEntry[i].peFlags = 0 ;

          incr = (incr == 9 ? 8 : 9) ;
     }

          // The following loop is responsible for 216 entries, but 8 of 
          //        them will match the standard 20 colors, and another
          //        4 of them will match the gray shades above.

     for (R = 0 ; R <= 0xFF ; R += 0x33)
     for (G = 0 ; G <= 0xFF ; G += 0x33)
     for (B = 0 ; B <= 0xFF ; B += 0x33)
     {
          plp->palPalEntry[i].peRed   = (BYTE) R ;
          plp->palPalEntry[i].peGreen = (BYTE) G ;
          plp->palPalEntry[i].peBlue  = (BYTE) B ;
          plp->palPalEntry[i].peFlags = 0 ;

          i++ ;
     }
     hPalette = CreatePalette (plp) ;

     free (plp) ;
     return hPalette ;
}
Example #23
0
/* Open the win_ddb driver */
static int
win_ddb_open(gx_device * dev)
{
    int code = win_open(dev);
    HDC hdc;

    if (code < 0)
	return code;

    if (wdev->BitsPerPixel > 8)
	return gs_error_limitcheck;	/* don't support 24 bit/pixel */

    /* Create the backing bitmap. */
    code = win_ddb_alloc_bitmap((gx_device_win *) dev, dev);
    if (code < 0)
	return code;

    /* Create the bitmap and DC for copy_mono. */
    hdc = GetDC(wdev->hwndimg);
    wdev->hbmmono = CreateBitmap(bmWidthBits, bmHeight, 1, 1, NULL);
    wdev->hdcmono = CreateCompatibleDC(hdc);
    if (wdev->hbmmono == NULL || wdev->hdcmono == NULL) {
	win_ddb_free_bitmap((gx_device_win *) dev);
	ReleaseDC(wdev->hwndimg, hdc);
	return win_nomemory();
    }
    SetMapMode(wdev->hdcmono, GetMapMode(hdc));
    SelectObject(wdev->hdcmono, wdev->hbmmono);
    wdev->bm_id = gx_no_bitmap_id;
    ReleaseDC(wdev->hwndimg, hdc);

    /* create palette and tools for bitmap */
    if ((wdev->lpalette = win_makepalette((gx_device_win *) dev))
	== (LPLOGPALETTE) NULL)
	return win_nomemory();
    wdev->hpalette = CreatePalette(wdev->lpalette);
    (void)SelectPalette(wdev->hdcbit, wdev->hpalette, NULL);
    RealizePalette(wdev->hdcbit);
    win_maketools(wdev, wdev->hdcbit);

    wdev->hdctext = wdev->hdcbit;	/* draw text here */

    return 0;
}
Example #24
0
void MakeBitmap(HDC hDC, RGBQUAD *pPalette, BYTE *pData)
{
   int           palette_size;
   int           dwSize;
   LPLOGPALETTE  lpMem;          // A mem pointer to the LOGPALETTE
   HANDLE        hMem;           // A handle to global memory
   int           index;

   palette_size = (1 << pbmi->bmiHeader.biBitCount);

   memcpy(pbmi->bmiColors, pPalette, palette_size * 4);

   dwSize = sizeof(LOGPALETTE) + (palette_size * sizeof(PALETTEENTRY));

   hMem = GlobalAlloc(GHND, dwSize);
   lpMem = (LPLOGPALETTE)GlobalLock(hMem);

   lpMem->palVersion    = 0x0300;
   lpMem->palNumEntries = palette_size;

   for (index=0; index < palette_size; index++)
   {
      lpMem->palPalEntry[index].peRed   = pPalette[index].rgbRed;
      lpMem->palPalEntry[index].peGreen = pPalette[index].rgbGreen;
      lpMem->palPalEntry[index].peBlue  = pPalette[index].rgbBlue;
      lpMem->palPalEntry[index].peFlags = 0;
   }

   if (hPalette)
      DeleteObject(hPalette);

   hPalette = CreatePalette(lpMem);

   GlobalUnlock(hMem);
   GlobalFree(hMem);

   if (hBitmap)
      DeleteObject(hBitmap);

   hBitmap = CreateDIBSection(hDC, pbmi, DIB_RGB_COLORS,
                              (VOID **)&pBitmapData, NULL, 0);

   memcpy(pBitmapData, pData, pbmi->bmiHeader.biSizeImage);
}
Example #25
0
void
palette_init(HWND hWnd)
{
#ifdef HAVE_COLOR_PALETTE
	HDC hdc;
	PAINTSTRUCT ps;
	LOGPALETTE* logpal;

	debug_printf(TEXT("*** palette init ***\n"));
	
	hdc = BeginPaint(hWnd, &ps);
	if (GetDeviceCaps(hdc, TECHNOLOGY) == DT_RASDISPLAY &&
	    (GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE) &&
	    GetDeviceCaps(hdc, COLORRES) == 8) {
		ASSERT(GetDeviceCaps(hdc, BITSPIXEL) == 8);
		ASSERT(GetDeviceCaps(hdc, PLANES) == 1);
		/*
		 * create logical palette
		 */
		logpal = LocalAlloc (LPTR,
				     (sizeof(LOGPALETTE) +
				      sizeof(PALETTEENTRY) * 256));
		logpal->palVersion = 0x300;
		logpal->palNumEntries = 256;
		palette_setup(logpal->palPalEntry);

		pal = CreatePalette(logpal);
		if (pal == NULL) {
			debug_printf(TEXT("CreatePalette() failed"));
			msg_printf(MSG_ERROR, TEXT("Error"),
				   TEXT("CreatePalette() failed: %d"),
				   GetLastError());
		}
		LocalFree((HLOCAL)logpal);
	} else {
		/*
		 * The screen is not 8 bit depth nor indexed color.
		 */
		palette_succeeded = PAL_NOERROR;
	}
	EndPaint(hWnd, &ps);
#endif /* HAVE_COLOR_PALETTE */
}
Example #26
0
void
paletteinit(void)
{
	PALETTEENTRY *pal;
	int r, g, b, cr, cg, cb, v;
	int num, den;
	int i, j;

	logpal = mallocz(sizeof(LOGPALETTE) + 256*sizeof(PALETTEENTRY), 1);
	if(logpal == nil)
		panic("out of memory");
	logpal->palVersion = 0x300;
	logpal->palNumEntries = 256;
	pal = logpal->palPalEntry;

	for(r=0,i=0; r<4; r++) {
		for(v=0; v<4; v++,i+=16){
			for(g=0,j=v-r; g<4; g++) {
				for(b=0; b<4; b++,j++){
					den=r;
					if(g>den)
						den=g;
					if(b>den)
						den=b;
					/* divide check -- pick grey shades */
					if(den==0)
						cr=cg=cb=v*17;
					else{
						num=17*(4*den+v);
						cr=r*num/den;
						cg=g*num/den;
						cb=b*num/den;
					}
					pal[i+(j&15)].peRed = cr;
					pal[i+(j&15)].peGreen = cg;
					pal[i+(j&15)].peBlue = cb;
					pal[i+(j&15)].peFlags = 0;
				}
			}
		}
	}
	palette = CreatePalette(logpal);
}
Example #27
0
HPALETTE GetQlibPalette()
{
	static HPALETTE hQlibPalette;
	if(hQlibPalette) return hQlibPalette;
	Draw::InitColors();
	LOGPALETTE *pal = (LOGPALETTE *) new byte[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)];
	pal->palNumEntries = 0;
	pal->palVersion    = 0x300;
	for(int r = 0; r < 6; r++)
		for(int g = 0; g < 6; g++)
			for(int b = 0; b < 6; b++)
				Add(pal, 255 * r / 5, 255 * g / 5, 255 * b / 5);
	for(int q = 0; q <= 16; q++)
		Add(pal, 16 * q, 16 * q, 16 * q);
	Add(pal, GetRValue(sLightGray), GetGValue(sLightGray), GetBValue(sLightGray));
	hQlibPalette = CreatePalette(pal);
	delete[] pal;
	return hQlibPalette;
}
Example #28
0
/***********************************************************************
 * CreateHalftonePalette [[email protected]]
 *
 * Creates a halftone palette.
 *
 * RETURNS
 *    Success: Handle to logical halftone palette
 *    Failure: 0
 *
 * FIXME: This simply creates the halftone palette derived from running
 *        tests on a windows NT machine. This is assuming a color depth
 *        of greater that 256 color. On a 256 color device the halftone
 *        palette will be different and this function will be incorrect
 */
HPALETTE WINAPI CreateHalftonePalette(
    HDC hdc) /* [in] Handle to device context */
{
    const RGBQUAD *entries = get_default_color_table( 8 );
    char buffer[FIELD_OFFSET( LOGPALETTE, palPalEntry[256] )];
    LOGPALETTE *pal = (LOGPALETTE *)buffer;
    int i;

    pal->palVersion = 0x300;
    pal->palNumEntries = 256;
    for (i = 0; i < 256; i++)
    {
        pal->palPalEntry[i].peRed   = entries[i].rgbRed;
        pal->palPalEntry[i].peGreen = entries[i].rgbGreen;
        pal->palPalEntry[i].peBlue  = entries[i].rgbBlue;
        pal->palPalEntry[i].peFlags = 0;
    }
    return CreatePalette( pal );
}
Example #29
0
extern Graphics::TBitmap* CreateBitmap(int width, int height, TPixelFormat pixelFormat)
{
  if (pixelFormat != pf1bit &&
      pixelFormat != pf8bit &&
      pixelFormat != pf24bit) return NULL;

  Graphics::TBitmap *Bitmap;

  RGBQUAD *oldColors;
  LOGPALETTE* pal = NULL;
  try
  {
    Bitmap = new Graphics::TBitmap();
    if (Bitmap == NULL) return NULL;
    Bitmap->PixelFormat = pixelFormat;
    Bitmap->HandleType = bmDIB;
    Bitmap->Width = width;
    Bitmap->Height = height;

    if (pixelFormat == pf8bit)
    {
      pal = (LOGPALETTE*) malloc( sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * 256);
      pal->palVersion = 0x300;
      pal->palNumEntries = 256;
      for(short i = 0 ; i < 256 ; i++)
      {
        pal->palPalEntry[i].peRed =  (Byte)i;
        pal->palPalEntry[i].peGreen = (Byte)i;
        pal->palPalEntry[i].peBlue = (Byte)i;
      }

      HPALETTE hpal = CreatePalette(pal);
      if(hpal) Bitmap->Palette = hpal;
    }
  }
  __finally
  {
    if (pal != NULL) delete pal;
  }

  return Bitmap;
}
Example #30
0
// ****************************************************************************
//
//  Function Name:	CreateDIBPalette( )
//
//  Description:		Create device independent palette from BITMAPINFO structure
//
//  Returns:			palette handle
//
//  Exceptions:		None
//
// ****************************************************************************
//
HPALETTE CreateDIBPalette (LPBITMAPINFO lpbmi, LPINT lpiNumColors)
{
   LPBITMAPINFOHEADER  lpbi;
   LPLOGPALETTE     lpPal;
   HANDLE           hLogPal;
   HPALETTE         hPal = NULL;
   int              i;
 
   lpbi = (LPBITMAPINFOHEADER)lpbmi;
   if (lpbi->biBitCount <= 8)
       *lpiNumColors = (1 << lpbi->biBitCount);
   else
       *lpiNumColors = 0;  // No palette needed for 24 BPP DIB
 
   if (*lpiNumColors)
      {
      hLogPal = GlobalAlloc (GHND, sizeof (LOGPALETTE) + sizeof (PALETTEENTRY) * (*lpiNumColors));

		if ( hLogPal != NULL )
		{
			lpPal = (LPLOGPALETTE) GlobalLock (hLogPal);

			if ( lpPal != NULL )
			{
				lpPal->palVersion    = 0x300;
				lpPal->palNumEntries = *lpiNumColors;
 
				for (i = 0;  i < *lpiNumColors;  i++)
					{
					lpPal->palPalEntry[i].peRed   = lpbmi->bmiColors[i].rgbRed;
					lpPal->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen;
					lpPal->palPalEntry[i].peBlue  = lpbmi->bmiColors[i].rgbBlue;
					lpPal->palPalEntry[i].peFlags = 0;
					}
				hPal = CreatePalette (lpPal);
				GlobalUnlock (hLogPal);
			}
			GlobalFree   (hLogPal);
		}
   }
   return hPal;
}