source: golgotha/src/maxtool/sdk_inc/gamma.h @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1/**********************************************************************
2 *<
3        FILE:  gamma.h
4
5        DESCRIPTION:  Gamma utilities
6
7        CREATED BY: Dan Silva
8
9        HISTORY: created 26 December 1995
10
11 *>     Copyright (c) 1995, All Rights Reserved.
12 **********************************************************************/
13
14
15#ifndef __GAMMA__H
16#define __GAMMA__H
17
18#define WRDMAX 65535
19#define FWRDMAX 65535.0f
20
21#define RCBITS 13   // number of bits used to represent colors before gamma correction.
22                                        // this keeps the lookup table a reasonable size
23#define RCOLN (1<<RCBITS)   
24#define RCMAX (RCOLN-1)
25#define FRCMAX ((float)RCMAX)
26#define RCHALF (RCOLN>>1)
27#define RCSH (RCBITS-8)           /* shift amount from 8 bit to RCBITS */
28#define RCSH16 (16-RCBITS)        /* shift amount from 16 bit to RCBITS */
29#define RCFRACMASK ((ulong)((1<<RCSH)-1))         
30#define RC_SCL (1<<RCSH)
31#define RC_SCLHALF (1<<(RCSH-1))
32#define FRC_SCL ((float)RC_SCL)
33#define RCSHMASK (0xffffffffL<<RCSH)
34#define RCSHMAX (0xffL<<RCSH)
35
36
37#define GAMMA_NTSC              2.2f
38#define GAMMA_PAL               2.8f
39
40class GammaMgr {
41        public:
42                BOOL enable;
43                BOOL dithTrue;
44                BOOL dithPaletted;
45                float dispGamma;
46                float fileInGamma;
47                float fileOutGamma;
48                UBYTE disp_gamtab[256];           // (8->8) display gamma for drawing color swatches (8->8)
49                UBYTE disp_gamtabw[RCOLN];    // (RCBITS->8) display gamma
50                UBYTE file_in_gamtab[256];    // (8->8)
51                UWORD file_in_degamtab[256];  // (8->16)  for de-gamifying bitmaps on input
52                UWORD file_out_gamtab[RCOLN]; // (RCBITS->16) gamma correct for file output, before dither
53
54                inline COLORREF DisplayGammaCorrect(COLORREF col) {
55                        return RGB(disp_gamtab[GetRValue(col)], disp_gamtab[GetGValue(col)], disp_gamtab[GetBValue(col)]);             
56                        }
57
58                CoreExport Color DisplayGammaCorrect(Color c);
59                       
60                CoreExport void Enable(BOOL onOff);
61                BOOL IsEnabled() { return enable;}
62
63                CoreExport void  SetDisplayGamma(float gam);
64                float GetDisplayGamma() { return dispGamma; }
65
66                CoreExport void SetFileInGamma(float gam);
67                float GetFileInGamma() { return fileInGamma; }
68
69                CoreExport void SetFileOutGamma(float gam);
70                float GetFileOutGamma() { return fileOutGamma; }
71
72                GammaMgr();
73
74
75        };
76
77CoreExport extern GammaMgr gammaMgr;
78
79
80inline COLORREF gammaCorrect(DWORD c) { return gammaMgr.DisplayGammaCorrect(c); }
81inline UBYTE gammaCorrect(UBYTE b) { return gammaMgr.disp_gamtab[b]; }
82
83
84#define GAMMA16to8(b)  gammaMgr.disp_gamtabw[b>>RCSH16]
85
86// Build Gamma table that maps 8->8 
87CoreExport void BuildGammaTab8(UBYTE gamtab[256], float gamma, int onoff=TRUE);
88
89// Build a Gamma table that maps 8->16
90CoreExport void BuildGammaTab8(UWORD gamtab[256], float gamma, int onoff=TRUE);
91
92// Build Gamma table that maps RCBITS->8
93CoreExport void BuildGammaTab(UBYTE gamtab[RCOLN], float gamma, int onoff=TRUE);
94
95// Build Gamma table that  maps RCBITS->16
96CoreExport void BuildGammaTab(UWORD gamtab[RCOLN], float gamma, int onoff=TRUE);
97
98CoreExport float gammaCorrect(float v, float gamma);
99CoreExport float deGammaCorrect(float v, float gamma);
100CoreExport UBYTE gammaCorrect(UBYTE v, float gamma);
101CoreExport UBYTE deGammaCorrect(UBYTE v, float gamma);
102CoreExport UWORD gammaCorrect(UWORD c, float gamma);
103CoreExport UWORD deGammaCorrect(UWORD c, float gamma);
104
105
106// Temporary table for converting 16->16.
107class GamConvert16 {
108        float gamma;
109        UWORD* gtab;
110        public:
111                GamConvert16(float gam=1.0f); 
112                ~ GamConvert16(); 
113                void SetGamma(float gam);
114                UWORD Convert(UWORD v) { return gtab[v>>RCSH16]; }
115
116        };
117
118// Temporary table for converting 8->16.
119class GamConvert8 {
120        float gamma;
121        UWORD gtab[256];
122        public:
123                GamConvert8(float gam=1.0f); 
124                void SetGamma(float gam);
125                UWORD Convert(UBYTE v) { return gtab[v]; }
126
127        };
128
129#endif
Note: See TracBrowser for help on using the repository browser.