30 static char rcsid[] =
"$Header: /l/spencer/src/urt/lib/RCS/dither.c,v 3.0.1.2 1992/04/30 14:07:02 spencer Exp $";
35 void make_square(
double,
int [256],
int [256],
int [16][16] );
48 #define DMAP(v,x,y) (modN[v]>magic[x][y] ? divN[v] + 1
: divN[v])
93 for ( i = 0; i < 256; i++ )
94 gammamap[i] = (
int)(0.5 + 255 * pow( i / 255.0, 1.0/gamma ));
96 levelsq = levels*levels;
97 levelsc = levels*levelsq;
99 N = 255.0 / (levels - 1);
104 for(i = 0; i < levelsc; i++) {
105 rgbmap[i][0] = gammamap[(
int)(0.5 + (i%levels) * N)];
106 rgbmap[i][1] = gammamap[(
int)(0.5 + ((i/levels)%levels) * N)];
107 rgbmap[i][2] = gammamap[(
int)(0.5 + ((i/levelsq)%levels) * N)];
154 for ( i = 0; i < 256; i++ )
155 gammamap[i] = (
int)(0.5 + 255 * pow( i / 255.0, 1.0/gamma ));
157 N = 255.0 / (levels - 1);
162 for(i = 0; i < levels; i++)
163 bwmap[i] = gammamap[(
int)(0.5 + i * N)];
198 register int i, j, k, l;
201 for ( i = 0; i < 256; i++ )
203 divN[i] = (
int)(i / N);
204 modN[i] = i - (
int)(N * divN[i]);
217 magicfact = (N - 1) / 16.;
218 for ( i = 0; i < 4; i++ )
219 for ( j = 0; j < 4; j++ )
220 for ( k = 0; k < 4; k++ )
221 for ( l = 0; l < 4; l++ )
222 magic[4*k+i][4*l+j] =
223 (
int)(0.5 +
magic4x4[i][j] * magicfact +
224 (
magic4x4[k][l] / 16.) * magicfact);
248 int x, y, r, g, b, levels;
253 int col = x % 16, row = y % 16;
255 return DMAP(r, col, row) +
256 DMAP(g, col, row) * levels +
257 DMAP(b, col, row) * levels*levels;
285 int col = x % 16, row = y % 16;
287 return DMAP(val, col, row);
void make_square(double N, divN, modN, magic)
void dithermap(int levels, double gamma, rgbmap, divN, modN, magic)
int ditherbw(int x, int y, int val, divN, modN, magic)
static int magic4x4[4][4]
int dithergb(int x, int y, int r, int g, int b, int levels, divN, modN, magic)
void bwdithermap(int levels, double gamma, bwmap, divN, modN, magic)