ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/biq.c
Revision: 2.4
Committed: Mon Jun 30 14:59:12 2003 UTC (20 years, 10 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.3: +4 -2 lines
Log Message:
Replaced most outdated BSD function calls with their posix equivalents, and cleaned up a few other platform dependencies.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: biq.c,v 2.3 2003/05/13 17:58:33 greg Exp $";
3 #endif
4 /*
5 * biq.c - simple greyscale quantization.
6 *
7 * 9/19/88
8 */
9
10 #include <string.h>
11
12 #include "standard.h"
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 memcpy((void *)cm,(void *)color,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((void *)linin);
64 free((void *)linout);
65 }