1 |
– |
/* Copyright 1988 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
CIQ - main program for color image quantization |
6 |
|
options for Floyd-Steinberg dithering by minimization of accumulated error |
10 |
|
Greg Ward 1 March 88, modified for arbitrary picture sizes |
11 |
|
*/ |
12 |
|
|
13 |
+ |
#include <string.h> |
14 |
+ |
|
15 |
+ |
#include "standard.h" |
16 |
|
#include "ciq.h" |
17 |
|
|
18 |
|
#define table(m,r,g,b) hist[m[0][r]|m[1][g]|m[2][b]] /* histogram/pvtable */ |
25 |
|
#define ERRMAX 20 /* maximum allowed propagated error, |
26 |
|
if >=255 then no clamping */ |
27 |
|
|
28 |
+ |
static void sample(colormap ocm); |
29 |
+ |
static void convertmap(colormap in, colormap out); |
30 |
+ |
static void draw_nodith(colormap ocm); |
31 |
+ |
static void draw_dith(colormap ocm); |
32 |
+ |
|
33 |
+ |
|
34 |
|
/*----------------------------------------------------------------------*/ |
35 |
|
|
36 |
< |
ciq(dith,nw,synth,cm) |
37 |
< |
int dith; /* is dithering desired? 0=no, 1=yes */ |
38 |
< |
int nw; /* number of colors wanted in output image */ |
39 |
< |
int synth; /* synthesize colormap? 0=no, 1=yes */ |
40 |
< |
colormap cm; /* quantization colormap */ |
41 |
< |
/* read if synth=0; always written */ |
36 |
> |
void |
37 |
> |
ciq( |
38 |
> |
int dith, /* is dithering desired? 0=no, 1=yes */ |
39 |
> |
int nw, /* number of colors wanted in output image */ |
40 |
> |
int synth, /* synthesize colormap? 0=no, 1=yes */ |
41 |
> |
colormap cm /* quantization colormap */ |
42 |
> |
) /* read if synth=0; always written */ |
43 |
|
{ |
44 |
|
int na,i; |
45 |
|
colormap ocm; |
50 |
|
if (synth) |
51 |
|
n = makecm(nw,&na); /* analyze histogram and synthesize colormap */ |
52 |
|
else { |
53 |
< |
bcopy((char *)cm,(char *)color,sizeof color); |
53 |
> |
memcpy((void *)color,(void *)cm,sizeof color); |
54 |
|
n = nw; |
55 |
|
na = 0; |
56 |
|
for (i=0; i<len; i++) if (hist[i]) na++; |
67 |
|
draw_nodith(ocm); |
68 |
|
} |
69 |
|
|
70 |
< |
bcopy((char *)color,(char *)cm,sizeof color); |
70 |
> |
memcpy((void *)cm,(void *)color,sizeof color); |
71 |
|
/*endclosest();*/ |
72 |
|
} |
73 |
|
|
74 |
|
/*----------------------------------------------------------------------*/ |
75 |
|
|
76 |
< |
sample(ocm) /* make color frequency table (histogram) */ |
77 |
< |
colormap ocm; |
76 |
> |
static void |
77 |
> |
sample( /* make color frequency table (histogram) */ |
78 |
> |
colormap ocm |
79 |
> |
) |
80 |
|
{ |
81 |
|
register int x,y; |
82 |
|
register rgbpixel *lp; |
94 |
|
for (lp=line, x=0; x<xmax; x++, lp++) |
95 |
|
table(map,lp->r,lp->g,lp->b)++; |
96 |
|
} |
97 |
< |
free((char *)line); |
97 |
> |
free((void *)line); |
98 |
|
} |
99 |
|
|
100 |
< |
convertmap(in,out) /* convert to shifted color map */ |
101 |
< |
register colormap in,out; |
100 |
> |
static void |
101 |
> |
convertmap( /* convert to shifted color map */ |
102 |
> |
register colormap in, |
103 |
> |
register colormap out |
104 |
> |
) |
105 |
|
{ |
106 |
|
register int j; |
107 |
|
|
112 |
|
} |
113 |
|
} |
114 |
|
|
115 |
< |
draw_nodith(ocm) /* quantize without dithering */ |
116 |
< |
colormap ocm; /* colormap for orig */ |
115 |
> |
static void |
116 |
> |
draw_nodith( /* quantize without dithering */ |
117 |
> |
colormap ocm /* colormap for orig */ |
118 |
> |
) |
119 |
|
{ |
120 |
|
register int x,y; |
121 |
|
register rgbpixel *lp; |
133 |
|
oline[x] = table(map,lp->r,lp->g,lp->b); |
134 |
|
picwriteline(y,oline); |
135 |
|
} |
136 |
< |
free((char *)iline); |
137 |
< |
free((char *)oline); |
136 |
> |
free((void *)iline); |
137 |
> |
free((void *)oline); |
138 |
|
} |
139 |
|
|
140 |
< |
draw_dith(ocm) /* quantize with dithering */ |
141 |
< |
colormap ocm; /* colormap for orig */ |
140 |
> |
static void |
141 |
> |
draw_dith( /* quantize with dithering */ |
142 |
> |
colormap ocm /* colormap for orig */ |
143 |
> |
) |
144 |
|
{ |
145 |
|
register int *p,*q,rr,gg,bb,v,x,y,*P,*Q,*R; |
146 |
|
int *buf; |
185 |
|
} |
186 |
|
picwriteline(y,oline); |
187 |
|
} |
188 |
< |
free((char *)iline); |
189 |
< |
free((char *)oline); |
190 |
< |
free((char *)buf); |
188 |
> |
free((void *)iline); |
189 |
> |
free((void *)oline); |
190 |
> |
free((void *)buf); |
191 |
|
} |