source: trunk/src/opengl/glide/cvg/init/gamma.c

Last change on this file was 6653, checked in by bird, 24 years ago

Added $Id:$ keyword.

File size: 8.1 KB
Line 
1/*-*-c++-*-*/
2/* $Id: gamma.c,v 1.2 2001-09-05 14:30:36 bird Exp $ */
3/*
4** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
5** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
6** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX
7** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE
8** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com).
9** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
10** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A
11** FULL TEXT OF THE NON-WARRANTY PROVISIONS.
12**
13** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
14** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
15** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013,
16** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
17** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
18** THE UNITED STATES.
19**
20** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
21**
22**
23** $Revision: 1.2 $
24** $Date: 2001-09-05 14:30:36 $
25**
26** Initialization code for loading SST-1 gamma tables
27**
28*/
29#pragma optimize ("",off)
30#include <stdio.h>
31#include <stdlib.h>
32#include <math.h>
33#ifdef BUILD_FOR_SST1
34#include <sst.h>
35#else
36#include <3dfx.h>
37#include <cvgregs.h>
38#include <cvgdefs.h>
39#endif
40#define FX_DLL_DEFINITION
41#include <fxdll.h>
42#include <sst1vid.h>
43#include <sst1init.h>
44
45/*
46** sst1InitGamma():
47** Load the video color-lookup tables with the specified gamma function
48**
49** Returns:
50** FXTRUE if successfully initializes SST-1 gamma tables
51** FXFALSE if cannot initialize SST-1 gamma tables
52**
53*/
54FX_EXPORT FxBool FX_CSTYLE sst1InitGamma(FxU32 *sstbase, double gamma)
55{
56 static FxBool calledBefore = FXFALSE;
57 static FxBool overRideR = FXFALSE;
58 static FxBool overRideG = FXFALSE;
59 static FxBool overRideB = FXFALSE;
60 static double gammaR, gammaG, gammaB;
61
62 if(!sstbase)
63 return(FXFALSE);
64
65 if(sst1InitCheckBoard(sstbase) == FXFALSE)
66 return(FXFALSE);
67
68 if(overRideR == FXFALSE)
69 gammaR = gamma;
70 if(overRideG == FXFALSE)
71 gammaG = gamma;
72 if(overRideB == FXFALSE)
73 gammaB = gamma;
74
75 if(calledBefore == FXFALSE) {
76 calledBefore = FXTRUE;
77 if(GETENV(("SSTV2_RGAMMA"))) {
78 overRideR = FXTRUE;
79 gammaR = (double) ATOF(GETENV(("SSTV2_RGAMMA")));
80 }
81 if(GETENV(("SSTV2_GGAMMA"))) {
82 overRideG = FXTRUE;
83 gammaG = (double) ATOF(GETENV(("SSTV2_GGAMMA")));
84 }
85 if(GETENV(("SSTV2_BGAMMA"))) {
86 overRideB = FXTRUE;
87 gammaB = (double) ATOF(GETENV(("SSTV2_BGAMMA")));
88 }
89 if(GETENV(("SSTV2_GAMMA"))) {
90 overRideR = FXTRUE;
91 overRideG = FXTRUE;
92 overRideB = FXTRUE;
93 gammaR = (double) ATOF(GETENV(("SSTV2_GAMMA")));
94 gammaG = gammaR;
95 gammaB = gammaR;
96 }
97 }
98 return(sst1InitGammaRGB(sstbase, gammaR, gammaG, gammaB));
99}
100
101FX_EXPORT FxBool FX_CSTYLE sst1InitGammaRGB(FxU32 *sstbase, double gammaR,
102 double gammaG, double gammaB)
103{
104 FxU32 x;
105 FxU32 gammaTableR[256];
106 FxU32 gammaTableG[256];
107 FxU32 gammaTableB[256];
108 FxBool sstVideoIsReset;
109 SstRegs *sst = (SstRegs *) sstbase;
110
111 if(!sstbase)
112 return(FXFALSE);
113
114 if(sst1InitCheckBoard(sstbase) == FXFALSE)
115 return(FXFALSE);
116
117 if(!sst1CurrentBoard->fbiInitGammaDone)
118 INIT_PRINTF(("sst1InitGammaRGB(): Setting GammaRGB = (%.2f,%.2f,%.2f)\n",
119 gammaR, gammaG, gammaB));
120
121 // Initialize the gamma table
122 for(x=0; x<256; x++) {
123 gammaTableR[x] = FTOL (POW(x/255.0F, 1.0F/gammaR) * 255.0F + 0.5F);
124 gammaTableG[x] = FTOL (POW(x/255.0F, 1.0F/gammaG) * 255.0F + 0.5F);
125 gammaTableB[x] = FTOL (POW(x/255.0F, 1.0F/gammaB) * 255.0F + 0.5F);
126 }
127
128 // Store gamma values in board info structure
129 sst1CurrentBoard->fbiGammaRed = gammaR;
130 sst1CurrentBoard->fbiGammaGreen = gammaG;
131 sst1CurrentBoard->fbiGammaBlue = gammaB;
132
133 // SST-1 video reset must be inactive to load gamma tables
134 if(IGET(sst->fbiInit1) & SST_VIDEO_RESET) {
135 sstVideoIsReset = FXTRUE;
136 sst1InitIdleFBINoNOP(sstbase);
137 ISET(sst->fbiInit1, IGET(sst->fbiInit1) & ~SST_VIDEO_RESET);
138 // wait for video reset to be deasserted
139 sst1InitIdleFBINoNOP(sstbase);
140 } else
141 sstVideoIsReset = FXFALSE;
142
143 // SST-1 requires every eighth entry of the gamma table to be loaded,
144 // so only 32 basic writes are required. A 33rd write is used to load
145 // the top entry of the gamma table. The 33rd entry is necessary because
146 // SST-1 performs linear interpolation between each gamma table entry to
147 // generate 256 unique gamma-corrected values.
148 for(x=0; x<32; x++) {
149 FxU32 gcR = gammaTableR[(x<<3)];
150 FxU32 gcG = gammaTableG[(x<<3)];
151 FxU32 gcB = gammaTableB[(x<<3)];
152 ISET(sst->clutData, ((x<<SST_CLUTDATA_INDEX_SHIFT) |
153 (gcR<<SST_CLUTDATA_RED_SHIFT) |
154 (gcG<<SST_CLUTDATA_GREEN_SHIFT) |
155 (gcB<<SST_CLUTDATA_BLUE_SHIFT)));
156 }
157 // Last entry in the gamma table is stored as 0x0 to perform proper
158 // linear interpolation of the last 8 entries
159 // BUG Fix: Last entry in table needs to be 0xffffff for proper linear
160 // interpolation
161 ISET(sst->clutData, (32<<SST_CLUTDATA_INDEX_SHIFT) | 0xffffff);
162
163 if(sstVideoIsReset == FXTRUE) {
164 // wait for gamma table writes to complete
165 sst1InitIdleFBINoNOP(sstbase);
166 ISET(sst->fbiInit1, IGET(sst->fbiInit1) | SST_VIDEO_RESET);
167 sst1InitIdleFBINoNOP(sstbase);
168 }
169
170 if(!sst1CurrentBoard->fbiInitGammaDone) {
171 sst1CurrentBoard->fbiInitGammaDone = 1;
172 INIT_PRINTF(("sst1InitGammaRGB() exiting with status %d...\n", FXTRUE));
173 }
174
175 return(FXTRUE);
176}
177
178FX_EXPORT FxBool FX_CSTYLE sst1InitGammaTable(FxU32 *sstbase, FxU32 nentries, FxU32 *r, FxU32 *g, FxU32 *b)
179{
180 FxU32 x;
181 FxU32 gammaTableR[256];
182 FxU32 gammaTableG[256];
183 FxU32 gammaTableB[256];
184 FxBool sstVideoIsReset;
185 SstRegs *sst = (SstRegs *) sstbase;
186
187 if(!sstbase)
188 return(FXFALSE);
189
190 if(sst1InitCheckBoard(sstbase) == FXFALSE)
191 return(FXFALSE);
192
193 // Initialize the gamma table
194 for(x=0; x < nentries; x++) {
195 gammaTableR[x] = *r;
196 gammaTableG[x] = *g;
197 gammaTableB[x] = *b;
198 r++; g++; b++;
199 }
200
201 // SST-1 video reset must be inactive to load gamma tables
202 if(IGET(sst->fbiInit1) & SST_VIDEO_RESET) {
203 sstVideoIsReset = FXTRUE;
204 sst1InitIdleFBINoNOP(sstbase);
205 ISET(sst->fbiInit1, IGET(sst->fbiInit1) & ~SST_VIDEO_RESET);
206 // wait for video reset to be deasserted
207 sst1InitIdleFBINoNOP(sstbase);
208 } else
209 sstVideoIsReset = FXFALSE;
210
211 // SST-1 requires every eighth entry of the gamma table to be loaded,
212 // so only 32 basic writes are required. A 33rd write is used to load
213 // the top entry of the gamma table. The 33rd entry is necessary because
214 // SST-1 performs linear interpolation between each gamma table entry to
215 // generate 256 unique gamma-corrected values.
216 for(x=0; x < nentries; x++) {
217 FxU32 gcR = gammaTableR[(x)];
218 FxU32 gcG = gammaTableG[(x)];
219 FxU32 gcB = gammaTableB[(x)];
220 ISET(sst->clutData, ((x<<SST_CLUTDATA_INDEX_SHIFT) |
221 (gcR<<SST_CLUTDATA_RED_SHIFT) |
222 (gcG<<SST_CLUTDATA_GREEN_SHIFT) |
223 (gcB<<SST_CLUTDATA_BLUE_SHIFT)));
224 }
225 // Last entry in the gamma table is stored as 0x0 to perform proper
226 // linear interpolation of the last 8 entries
227 // BUG Fix: Last entry in table needs to be 0xffffff for proper linear
228 // interpolation
229 ISET(sst->clutData, (32<<SST_CLUTDATA_INDEX_SHIFT) | 0xffffff);
230
231 if(sstVideoIsReset == FXTRUE) {
232 // wait for gamma table writes to complete
233 sst1InitIdleFBINoNOP(sstbase);
234 ISET(sst->fbiInit1, IGET(sst->fbiInit1) | SST_VIDEO_RESET);
235 sst1InitIdleFBINoNOP(sstbase);
236 }
237
238 return(FXTRUE);
239}
240
241#pragma optimize ("",on)
Note: See TracBrowser for help on using the repository browser.