25 #define bmalloc malloc 26 #if !defined(WIN32_VC) && !defined(WIN64_VC) 27 extern char *bmalloc(
int);
35 static BYTE *g_mant = NULL, *g_nexp = NULL;
37 static BYTE (*g_bval)[256] = NULL;
40 #if !defined(WIN32_VC) && !defined(WIN64_VC) 41 extern double pow(
double,
double);
46 int setcolrcor(
double (*f)(
double,
double),
double a2)
52 if (g_bval == NULL && (g_bval =
53 (BYTE (*)[256])bmalloc((MAXGSHIFT+1)*256)) == NULL)
57 for (i = 0; i <= MAXGSHIFT; i++) {
58 for (j = 0; j < 256; j++)
59 g_bval[i][j] = (BYTE) (256.0 * (*f)((j+.5)*mult, a2));
66 int setcolrinv(
double (*f)(
double,
double),
double a2)
72 if (g_mant == NULL && (g_mant = (BYTE *)bmalloc(256)) == NULL)
74 if (g_nexp == NULL && (g_nexp = (BYTE *)bmalloc(256)) == NULL)
79 for (j = 255; j > 0; j--) {
80 while ((g_mant[j] = (BYTE)(mult * (*f)(j/256.0, a2))) < 128) {
92 int setcolrgam(
double g)
94 if (setcolrcor(pow, 1.0/g) < 0)
96 return(setcolrinv(pow, g));
100 int colrs_gambs(COLR *scan,
int len)
108 expo = scan[0][EXP] - COLXS;
109 if (expo < -MAXGSHIFT) {
110 if (expo < -MAXGSHIFT-8) {
115 i = (-MAXGSHIFT-1) - expo;
117 g_bval[MAXGSHIFT][((scan[0][RED]>>i)+1)>>1];
119 g_bval[MAXGSHIFT][((scan[0][GRN]>>i)+1)>>1];
121 g_bval[MAXGSHIFT][((scan[0][BLU]>>i)+1)>>1];
123 }
else if (expo > 0) {
129 i = (scan[0][RED]<<1 | 1) << (expo-1);
130 scan[0][RED] = i > 255 ? 255 : g_bval[0][i];
131 i = (scan[0][GRN]<<1 | 1) << (expo-1);
132 scan[0][GRN] = i > 255 ? 255 : g_bval[0][i];
133 i = (scan[0][BLU]<<1 | 1) << (expo-1);
134 scan[0][BLU] = i > 255 ? 255 : g_bval[0][i];
137 scan[0][RED] = g_bval[-expo][scan[0][RED]];
138 scan[0][GRN] = g_bval[-expo][scan[0][GRN]];
139 scan[0][BLU] = g_bval[-expo][scan[0][BLU]];
141 scan[0][EXP] = COLXS;
148 int gambs_colrs(COLR *scan,
int len)
153 if (g_mant == NULL || g_nexp == NULL)
156 nexpo = g_nexp[scan[0][RED]];
157 if (g_nexp[scan[0][GRN]] < nexpo)
158 nexpo = g_nexp[scan[0][GRN]];
159 if (g_nexp[scan[0][BLU]] < nexpo)
160 nexpo = g_nexp[scan[0][BLU]];
161 if (nexpo < g_nexp[scan[0][RED]])
162 scan[0][RED] = g_mant[scan[0][RED]]
163 >> (g_nexp[scan[0][RED]]-nexpo);
165 scan[0][RED] = g_mant[scan[0][RED]];
166 if (nexpo < g_nexp[scan[0][GRN]])
167 scan[0][GRN] = g_mant[scan[0][GRN]]
168 >> (g_nexp[scan[0][GRN]]-nexpo);
170 scan[0][GRN] = g_mant[scan[0][GRN]];
171 if (nexpo < g_nexp[scan[0][BLU]])
172 scan[0][BLU] = g_mant[scan[0][BLU]]
173 >> (g_nexp[scan[0][BLU]]-nexpo);
175 scan[0][BLU] = g_mant[scan[0][BLU]];
176 scan[0][EXP] = COLXS - nexpo;
184 shiftcolrs(COLR *scan,
int len,
int adjust)
191 minexp = adjust < 0 ? -adjust : 0;
193 if (scan[0][EXP] <= minexp)
194 scan[0][RED] = scan[0][GRN] = scan[0][BLU] =
197 scan[0][EXP] += adjust;
204 normcolrs(COLR *scan,
int len,
int adjust)
211 shift = scan[0][EXP] + adjust - COLXS;
219 c = (scan[0][RED]<<1 | 1) << shift;
220 scan[0][RED] = c > 255 ? 255 : c;
221 c = (scan[0][GRN]<<1 | 1) << shift;
222 scan[0][GRN] = c > 255 ? 255 : c;
223 c = (scan[0][BLU]<<1 | 1) << shift;
224 scan[0][BLU] = c > 255 ? 255 : c;
226 }
else if (shift < 0) {
233 scan[0][RED] = ((scan[0][RED]>>shift)+1)>>1;
234 scan[0][GRN] = ((scan[0][GRN]>>shift)+1)>>1;
235 scan[0][BLU] = ((scan[0][BLU]>>shift)+1)>>1;
238 scan[0][EXP] = COLXS - adjust;