1 /*
2  * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 #ifndef AWT_PALETTE_H
27 #define AWT_PALETTE_H
28 
29 #include "awt_Win32GraphicsDevice.h"
30 
31 #define CMAPSIZE        256     // number of colors to use in default cmap
32 
33 #define GS_NOTGRAY      0       // screen is not grayscale
34 #define GS_INDEXGRAY    1       // screen is 8-bit indexed with several
35                                 //  gray colormap entries
36 #define GS_STATICGRAY   2       // screen is 8-bit with 256 gray values
37                                 // from 0 to 255 (no index table used)
38 #define GS_NONLINGRAY   3       /* screen is 8-bit with 256 gray values
39                                    in non-monotonic order */
40 
41 class AwtWin32GraphicsDevice;
42 
43 class AwtPalette {
44 
45 public:
46     HPALETTE                Select(HDC hDC);
47 
48     void                    Realize(HDC hDC);
49 
GetPalette()50     HPALETTE                GetPalette() { return logicalPalette; }
51 
52                             AwtPalette(AwtWin32GraphicsDevice *device);
53 
54     static int              FetchPaletteEntries(HDC hDC, PALETTEENTRY* pPalEntries);
55     int                     GetGSType(PALETTEENTRY* pPalEntries);
56 
57     BOOL                    Update();
58     void                    UpdateLogical();
59 
GetSystemEntries()60     unsigned int            *GetSystemEntries() {return systemEntries; }
GetLogicalEntries()61     unsigned int            *GetLogicalEntries() {return logicalEntries; }
GetSystemInverseLUT()62     unsigned char           *GetSystemInverseLUT() { return systemInverseLUT; }
63 
64 private:
65     unsigned int            logicalEntries[256];
66     unsigned int            systemEntries[256];
67     PALETTEENTRY            systemEntriesWin32[256];  // cached to eliminate
68                                               // copying it when unnec.
69     int                     numSystemEntries;
70     HPALETTE                logicalPalette;
71 
72     AwtWin32GraphicsDevice  *device;
73     unsigned char           *systemInverseLUT;
74 
75     /**
76      * This custom palette is derived from the IE palette.
77      * Previously, we used a custom palette that used a patented
78      * algorithm for getting an evently distributed color space.
79      * But given the realites of desktop and web graphics, it seems
80      * more important to use a more standard palette, especially one
81      * that agrees with the predominant browser.  The browser uses
82      * a slightly modified 6x6x6 colorcube plus a gray ramp plus a
83      * few other colors.  We still flash with Netscape, but we end
84      * up using a very similar palette (Netscape uses a 6x6x6 color
85      * cube as well); the entries are just in different places (thus
86      * the flash).
87      * Another possible solution to use a standard palette would be
88      * to use the CreateHalftonePalette() call of win32.  This gives
89      * us the IE palette on win98, but totally different palettes on
90      * different versions of Windows.  We should at least use the same
91      * colors on different flavors of the same platform...
92      * The values coded below should be used for entries 10 through
93      * 245 of our custom palette.  Entries 0-9 and 246-255 should be
94      * retrieved from the current system palette, to ensure that we
95      * are working well with the current desktop palette.
96      *
97      * The palette is initialized in awt_CustomPaletteDef.h
98      */
99     static PALETTEENTRY     customPalette[236];
100 };
101 
102 
103 
104 #endif AWT_PALETTE_H
105