1 |
/* Copyright 1988 Regents of the University of California */ |
2 |
|
3 |
#ifndef lint |
4 |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
#endif |
6 |
|
7 |
/* |
8 |
* biq.c - simple greyscale quantization. |
9 |
* |
10 |
* 9/19/88 |
11 |
*/ |
12 |
|
13 |
#include "ciq.h" |
14 |
|
15 |
|
16 |
biq(dith,nw,synth,cm) |
17 |
int dith; /* is dithering desired? 0=no, 1=yes */ |
18 |
int nw; /* number of colors wanted in output image */ |
19 |
int synth; /* synthesize colormap? 0=no, 1=yes */ |
20 |
colormap cm; /* quantization colormap */ |
21 |
/* read if synth=0; always written */ |
22 |
{ |
23 |
colormap ocm; |
24 |
|
25 |
picreadcm(ocm); /* read original picture's colormap (usually identity)*/ |
26 |
|
27 |
for (n = 0; n < nw; n++) /* also sets n to nw */ |
28 |
color[0][n] = color[1][n] = color[2][n] = (n*256L+128)/nw; |
29 |
|
30 |
picwritecm(color); |
31 |
|
32 |
draw_grey(ocm); |
33 |
|
34 |
bcopy(color,cm,sizeof color); |
35 |
} |
36 |
|
37 |
/*----------------------------------------------------------------------*/ |
38 |
|
39 |
draw_grey(ocm) |
40 |
colormap ocm; |
41 |
{ |
42 |
register rgbpixel *linin; |
43 |
register pixel *linout; |
44 |
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 |
linin[x].r = ocm[0][linin[x].r]; |
54 |
linin[x].g = ocm[1][linin[x].g]; |
55 |
linin[x].b = ocm[2][linin[x].b]; |
56 |
linout[x] = rgb_bright(&linin[x]); |
57 |
linout[x] = (linout[x]*n+n/2)/256; |
58 |
} |
59 |
picwriteline(y, linout); |
60 |
} |
61 |
free((char *)linin); |
62 |
free((char *)linout); |
63 |
} |