1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.2 |
static const char RCSid[] = "$Id$"; |
3 |
greg |
1.1 |
#endif |
4 |
greg |
1.2 |
/* |
5 |
greg |
1.1 |
* biq.c - simple greyscale quantization. |
6 |
|
|
* |
7 |
|
|
* 9/19/88 |
8 |
|
|
*/ |
9 |
|
|
|
10 |
greg |
1.5 |
#include "standard.h" |
11 |
greg |
1.1 |
#include "ciq.h" |
12 |
|
|
|
13 |
|
|
|
14 |
|
|
biq(dith,nw,synth,cm) |
15 |
|
|
int dith; /* is dithering desired? 0=no, 1=yes */ |
16 |
|
|
int nw; /* number of colors wanted in output image */ |
17 |
|
|
int synth; /* synthesize colormap? 0=no, 1=yes */ |
18 |
|
|
colormap cm; /* quantization colormap */ |
19 |
|
|
/* read if synth=0; always written */ |
20 |
|
|
{ |
21 |
|
|
colormap ocm; |
22 |
|
|
|
23 |
|
|
picreadcm(ocm); /* read original picture's colormap (usually identity)*/ |
24 |
|
|
|
25 |
|
|
for (n = 0; n < nw; n++) /* also sets n to nw */ |
26 |
|
|
color[0][n] = color[1][n] = color[2][n] = (n*256L+128)/nw; |
27 |
|
|
|
28 |
|
|
picwritecm(color); |
29 |
|
|
|
30 |
|
|
draw_grey(ocm); |
31 |
|
|
|
32 |
greg |
2.3 |
bcopy((void *)color,(void *)cm,sizeof color); |
33 |
greg |
1.1 |
} |
34 |
|
|
|
35 |
|
|
/*----------------------------------------------------------------------*/ |
36 |
|
|
|
37 |
|
|
draw_grey(ocm) |
38 |
|
|
colormap ocm; |
39 |
|
|
{ |
40 |
|
|
register rgbpixel *linin; |
41 |
|
|
register pixel *linout; |
42 |
greg |
1.3 |
rgbpixel intmp; |
43 |
|
|
int outtmp; |
44 |
greg |
1.1 |
int y; |
45 |
|
|
register int x; |
46 |
|
|
|
47 |
|
|
linin = line3alloc(xmax); |
48 |
|
|
linout = linealloc(xmax); |
49 |
|
|
|
50 |
|
|
for (y = 0; y < ymax; y++) { |
51 |
|
|
picreadline3(y, linin); |
52 |
|
|
for (x = 0; x < xmax; x++) { |
53 |
greg |
1.3 |
intmp.r = ocm[0][linin[x].r]; |
54 |
|
|
intmp.g = ocm[1][linin[x].g]; |
55 |
|
|
intmp.b = ocm[2][linin[x].b]; |
56 |
|
|
outtmp = rgb_bright(&intmp); |
57 |
|
|
linout[x] = (outtmp*n+n/2)/256; |
58 |
greg |
1.1 |
} |
59 |
|
|
picwriteline(y, linout); |
60 |
|
|
} |
61 |
greg |
2.2 |
free((void *)linin); |
62 |
|
|
free((void *)linout); |
63 |
greg |
1.1 |
} |