ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/biq.c
Revision: 1.4
Committed: Thu Jan 18 23:58:12 1990 UTC (34 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +1 -1 lines
Log Message:
improved portability for read(), write() and bcopy()

File Contents

# Content
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((char *)color,(char *)cm,sizeof color);
35 }
36
37 /*----------------------------------------------------------------------*/
38
39 draw_grey(ocm)
40 colormap ocm;
41 {
42 register rgbpixel *linin;
43 register pixel *linout;
44 rgbpixel intmp;
45 int outtmp;
46 int y;
47 register int x;
48
49 linin = line3alloc(xmax);
50 linout = linealloc(xmax);
51
52 for (y = 0; y < ymax; y++) {
53 picreadline3(y, linin);
54 for (x = 0; x < xmax; x++) {
55 intmp.r = ocm[0][linin[x].r];
56 intmp.g = ocm[1][linin[x].g];
57 intmp.b = ocm[2][linin[x].b];
58 outtmp = rgb_bright(&intmp);
59 linout[x] = (outtmp*n+n/2)/256;
60 }
61 picwriteline(y, linout);
62 }
63 free((char *)linin);
64 free((char *)linout);
65 }