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 |
|
|
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((void *)cm,(void *)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((void *)color,(void *)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; |
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; |
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; |