ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/biq.c
Revision: 2.5
Committed: Sun Mar 28 20:33:13 2004 UTC (20 years, 1 month ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6P1, rad3R6
Changes since 2.4: +15 -9 lines
Log Message:
Continued ANSIfication, and other fixes and clarifications.

File Contents

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