| 1 | /* $Id: palette.cpp,v 1.13 2004-04-14 09:44:14 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * GDI32 palette apis | 
|---|
| 5 | * | 
|---|
| 6 | * Based on Wine code (991031) (objects\palette.c) | 
|---|
| 7 | * | 
|---|
| 8 | * Copyright 1993,1994 Alexandre Julliard | 
|---|
| 9 | * Copyright 1996 Alex Korobka | 
|---|
| 10 | * | 
|---|
| 11 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 12 | * | 
|---|
| 13 | */ | 
|---|
| 14 | #include <os2win.h> | 
|---|
| 15 | #include <stdlib.h> | 
|---|
| 16 | #include <misc.h> | 
|---|
| 17 | #include <string.h> | 
|---|
| 18 | #include "dibsect.h" | 
|---|
| 19 |  | 
|---|
| 20 | #define DBG_LOCALLOG    DBG_palette | 
|---|
| 21 | #include "dbglocal.h" | 
|---|
| 22 |  | 
|---|
| 23 | static UINT SystemPaletteUse = SYSPAL_STATIC;  /* currently not considered */ | 
|---|
| 24 |  | 
|---|
| 25 | /*********************************************************************** | 
|---|
| 26 | * SetSystemPaletteUse32 [GDI32.335] | 
|---|
| 27 | * | 
|---|
| 28 | * RETURNS | 
|---|
| 29 | *    Success: Previous system palette | 
|---|
| 30 | *    Failure: SYSPAL_ERROR | 
|---|
| 31 | */ | 
|---|
| 32 | UINT WINAPI SetSystemPaletteUse( | 
|---|
| 33 | HDC hdc,  /* [in] Handle of device context */ | 
|---|
| 34 | UINT use) /* [in] Palette-usage flag */ | 
|---|
| 35 | { | 
|---|
| 36 | UINT old = SystemPaletteUse; | 
|---|
| 37 | dprintf(("SetSystemPaletteUse: (%04x,%04x): stub\n", hdc, use )); | 
|---|
| 38 | SystemPaletteUse = use; | 
|---|
| 39 | return old; | 
|---|
| 40 | } | 
|---|
| 41 | /*********************************************************************** | 
|---|
| 42 | * GetSystemPaletteUse32 [GDI32.223]  Gets state of system palette | 
|---|
| 43 | * | 
|---|
| 44 | * RETURNS | 
|---|
| 45 | *    Current state of system palette | 
|---|
| 46 | */ | 
|---|
| 47 | UINT WINAPI GetSystemPaletteUse(HDC hdc) /* [in] Handle of device context */ | 
|---|
| 48 | { | 
|---|
| 49 | dprintf(("GetSystemPaletteUse %x", hdc)); | 
|---|
| 50 | return SystemPaletteUse; | 
|---|
| 51 | } | 
|---|
| 52 | //****************************************************************************** | 
|---|
| 53 | //****************************************************************************** | 
|---|
| 54 | UINT WIN32API RealizePalette( HDC hdc) | 
|---|
| 55 | { | 
|---|
| 56 | UINT rc; | 
|---|
| 57 |  | 
|---|
| 58 | rc = O32_RealizePalette(hdc); | 
|---|
| 59 | dprintf(("GDI32: RealizePalette %x returned %d", hdc, rc)); | 
|---|
| 60 | if(rc) | 
|---|
| 61 | { | 
|---|
| 62 | DIBSECTION_MARK_INVALID(hdc); | 
|---|
| 63 | } | 
|---|
| 64 | return rc; | 
|---|
| 65 | } | 
|---|
| 66 | //****************************************************************************** | 
|---|
| 67 | //****************************************************************************** | 
|---|
| 68 | HPALETTE WIN32API CreatePalette( const LOGPALETTE * arg1) | 
|---|
| 69 | { | 
|---|
| 70 | HPALETTE rc; | 
|---|
| 71 |  | 
|---|
| 72 | #ifdef DEBUG | 
|---|
| 73 | for(int i=0; i<arg1->palNumEntries;i++) | 
|---|
| 74 | { | 
|---|
| 75 | dprintf2(("Index %d : 0x%08X\n",i, *((DWORD*)(&arg1->palPalEntry[i])) )); | 
|---|
| 76 | } | 
|---|
| 77 | #endif | 
|---|
| 78 | rc = O32_CreatePalette(arg1); | 
|---|
| 79 | dprintf(("GDI32: CreatePalette %x %d returns 0x%08X\n", arg1, arg1->palNumEntries, rc)); | 
|---|
| 80 |  | 
|---|
| 81 | return rc; | 
|---|
| 82 | } | 
|---|
| 83 | //****************************************************************************** | 
|---|
| 84 | //****************************************************************************** | 
|---|
| 85 | HPALETTE WIN32API SelectPalette(HDC hdc, HPALETTE hPalette, BOOL bForceBackground) | 
|---|
| 86 | { | 
|---|
| 87 | HPALETTE hPal; | 
|---|
| 88 |  | 
|---|
| 89 | dprintf(("GDI32: SelectPalette (0x%08X, 0x%08X, 0x%08X)", hdc, hPalette, bForceBackground)); | 
|---|
| 90 | hPal = O32_SelectPalette(hdc, hPalette, bForceBackground); | 
|---|
| 91 | return hPal; | 
|---|
| 92 | } | 
|---|
| 93 | //****************************************************************************** | 
|---|
| 94 | //****************************************************************************** | 
|---|
| 95 | BOOL WIN32API AnimatePalette( HPALETTE arg1, UINT arg2, UINT arg3, const PALETTEENTRY * arg4) | 
|---|
| 96 | { | 
|---|
| 97 | dprintf(("GDI32: AnimatePalette")); | 
|---|
| 98 | return O32_AnimatePalette(arg1, arg2, arg3, arg4); | 
|---|
| 99 | } | 
|---|
| 100 | //****************************************************************************** | 
|---|
| 101 | //****************************************************************************** | 
|---|
| 102 | UINT WIN32API GetNearestPaletteIndex( HPALETTE arg1, COLORREF  arg2) | 
|---|
| 103 | { | 
|---|
| 104 | UINT rc; | 
|---|
| 105 | dprintf(("GDI32: GetNearestPaletteIndex (0x%08X ,0x%08X) ",arg1,arg2)); | 
|---|
| 106 | rc = O32_GetNearestPaletteIndex(arg1, arg2); | 
|---|
| 107 | dprintf(("Returns %d\n",rc)); | 
|---|
| 108 | return rc; | 
|---|
| 109 | } | 
|---|
| 110 | //****************************************************************************** | 
|---|
| 111 | //****************************************************************************** | 
|---|
| 112 | UINT WIN32API GetPaletteEntries(HPALETTE hPalette, UINT iStart, UINT count, PPALETTEENTRY entries) | 
|---|
| 113 | { | 
|---|
| 114 | UINT rc; | 
|---|
| 115 |  | 
|---|
| 116 | rc = O32_GetPaletteEntries(hPalette, iStart, count, entries); | 
|---|
| 117 | dprintf(("GDI32: GetPaletteEntries %x %d-%d %x returned %d", hPalette, iStart, count, entries, rc)); | 
|---|
| 118 | return rc; | 
|---|
| 119 | } | 
|---|
| 120 | //****************************************************************************** | 
|---|
| 121 | //****************************************************************************** | 
|---|
| 122 | UINT WIN32API GetSystemPaletteEntries( HDC arg1, UINT arg2, UINT arg3, PPALETTEENTRY  arg4) | 
|---|
| 123 | { | 
|---|
| 124 | UINT rc; | 
|---|
| 125 |  | 
|---|
| 126 | dprintf(("GDI32: GetSystemPaletteEntries start %d nr %d pal ptr %X", arg2, arg3, arg4)); | 
|---|
| 127 | rc = O32_GetSystemPaletteEntries(arg1, arg2, arg3, arg4); | 
|---|
| 128 | dprintf((" GetSystemPaletteEntries returned %d", rc)); | 
|---|
| 129 | return(rc); | 
|---|
| 130 | } | 
|---|
| 131 | //****************************************************************************** | 
|---|
| 132 | //****************************************************************************** | 
|---|
| 133 | BOOL WIN32API ResizePalette( HPALETTE arg1, UINT  arg2) | 
|---|
| 134 | { | 
|---|
| 135 | dprintf(("GDI32: ResizePalette\n")); | 
|---|
| 136 | return O32_ResizePalette(arg1, arg2); | 
|---|
| 137 | } | 
|---|
| 138 | //****************************************************************************** | 
|---|
| 139 | //****************************************************************************** | 
|---|
| 140 | UINT WIN32API SetPaletteEntries( HPALETTE hPalette, UINT arg2, UINT arg3, const PALETTEENTRY * arg4) | 
|---|
| 141 | { | 
|---|
| 142 | dprintf(("GDI32: SetPaletteEntries %x %d-%d %x", hPalette, arg2, arg3, arg4)); | 
|---|
| 143 | return O32_SetPaletteEntries(hPalette, arg2, arg3, (const PALETTEENTRY *)arg4); | 
|---|
| 144 | } | 
|---|
| 145 | //****************************************************************************** | 
|---|
| 146 | //****************************************************************************** | 
|---|
| 147 | HPALETTE WIN32API CreateHalftonePalette(HDC hdc) | 
|---|
| 148 | { | 
|---|
| 149 | int i, r, g, b; | 
|---|
| 150 | struct { | 
|---|
| 151 | WORD Version; | 
|---|
| 152 | WORD NumberOfEntries; | 
|---|
| 153 | PALETTEENTRY aEntries[256]; | 
|---|
| 154 | } Palette = { | 
|---|
| 155 | 0x300, 256 | 
|---|
| 156 | }; | 
|---|
| 157 |  | 
|---|
| 158 | dprintf(("GDI32: CreateHalftonePalette %x", hdc)); | 
|---|
| 159 | GetSystemPaletteEntries(hdc, 0, 256, Palette.aEntries); | 
|---|
| 160 | return CreatePalette((LOGPALETTE *)&Palette); | 
|---|
| 161 |  | 
|---|
| 162 | for (r = 0; r < 6; r++) { | 
|---|
| 163 | for (g = 0; g < 6; g++) { | 
|---|
| 164 | for (b = 0; b < 6; b++) { | 
|---|
| 165 | i = r + g*6 + b*36 + 10; | 
|---|
| 166 | Palette.aEntries[i].peRed = r * 51; | 
|---|
| 167 | Palette.aEntries[i].peGreen = g * 51; | 
|---|
| 168 | Palette.aEntries[i].peBlue = b * 51; | 
|---|
| 169 | } | 
|---|
| 170 | } | 
|---|
| 171 | } | 
|---|
| 172 |  | 
|---|
| 173 | for (i = 216; i < 246; i++) { | 
|---|
| 174 | int v = (i - 216) * 8; | 
|---|
| 175 | Palette.aEntries[i].peRed = v; | 
|---|
| 176 | Palette.aEntries[i].peGreen = v; | 
|---|
| 177 | Palette.aEntries[i].peBlue = v; | 
|---|
| 178 | } | 
|---|
| 179 |  | 
|---|
| 180 | return CreatePalette((LOGPALETTE *)&Palette); | 
|---|
| 181 | } | 
|---|
| 182 | //****************************************************************************** | 
|---|
| 183 | //****************************************************************************** | 
|---|