ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/biq.c
Revision: 1.1
Committed: Thu Feb 2 10:49:06 1989 UTC (35 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# Content
1 /*
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6 * biq.c - simple greyscale quantization.
7 *
8 * 9/19/88
9 */
10
11 #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 bcopy(color,cm,sizeof color);
33 }
34
35 /*----------------------------------------------------------------------*/
36
37 draw_grey(ocm)
38 colormap ocm;
39 {
40 register rgbpixel *linin;
41 register pixel *linout;
42 int y;
43 register int x;
44
45 linin = line3alloc(xmax);
46 linout = linealloc(xmax);
47
48 for (y = 0; y < ymax; y++) {
49 picreadline3(y, linin);
50 for (x = 0; x < xmax; x++) {
51 linin[x].r = ocm[0][linin[x].r];
52 linin[x].g = ocm[1][linin[x].g];
53 linin[x].b = ocm[2][linin[x].b];
54 linout[x] = rgb_bright(&linin[x]);
55 linout[x] = (linout[x]*n+n/2)/256;
56 }
57 picwriteline(y, linout);
58 }
59 free((char *)linin);
60 free((char *)linout);
61 }