update for HEAD-2003050101
[reactos.git] / subsys / win32k / eng / palette.c
1 /*
2  * COPYRIGHT:         See COPYING in the top level directory
3  * PROJECT:           ReactOS kernel
4  * PURPOSE:           GDI Palette Functions
5  * FILE:              subsys/win32k/eng/palette.c
6  * PROGRAMER:         Jason Filby
7  * REVISION HISTORY:
8  *                 11/7/1999: Created
9  */
10
11 #include <ddk/winddi.h>
12 #include <include/object.h>
13 #include "handle.h"
14
15 #define NDEBUG
16 #include <win32k/debug1.h>
17
18 HPALETTE STDCALL
19 EngCreatePalette(ULONG Mode,
20                  ULONG NumColors,
21                  ULONG *Colors,
22                  ULONG Red,
23                  ULONG Green,
24                  ULONG Blue)
25 {
26   HPALETTE NewPalette;
27   PALGDI *PalGDI;
28
29   NewPalette = (HPALETTE)CreateGDIHandle(sizeof(PALGDI), sizeof(PALOBJ));
30   if( !ValidEngHandle( NewPalette ) )
31         return 0;
32
33   PalGDI = (PALGDI*) AccessInternalObject( (ULONG) NewPalette );
34   ASSERT( PalGDI );
35
36   PalGDI->Mode = Mode;
37
38   if(Colors != NULL)
39   {
40     PalGDI->IndexedColors = ExAllocatePool(NonPagedPool, sizeof(PALETTEENTRY) * NumColors);
41     RtlCopyMemory(PalGDI->IndexedColors, Colors, sizeof(PALETTEENTRY) * NumColors);
42   }
43
44   if(Mode==PAL_INDEXED)
45   {
46     PalGDI->NumColors     = NumColors;
47   } else
48   if(Mode==PAL_BITFIELDS)
49   {
50     PalGDI->RedMask   = Red;
51     PalGDI->GreenMask = Green;
52     PalGDI->BlueMask  = Blue;
53   }
54
55   return NewPalette;
56 }
57
58 BOOL STDCALL
59 EngDeletePalette(IN HPALETTE Palette)
60 {
61   FreeGDIHandle((ULONG)Palette);
62   return TRUE;
63 }
64
65 ULONG STDCALL
66 PALOBJ_cGetColors(PALOBJ *PalObj,
67                   ULONG Start,
68                   ULONG Colors,
69                   ULONG *PaletteEntry)
70 {
71   ULONG i;
72   PALGDI *PalGDI;
73
74   PalGDI = (PALGDI*)AccessInternalObjectFromUserObject(PalObj);
75
76   for(i=Start; i<Colors; i++)
77   {
78     PaletteEntry[i] = PalGDI->IndexedColors[i];
79   }
80
81   return Colors;
82 }