33 |
|
|
34 |
|
long picstart; |
35 |
|
|
36 |
< |
extern BYTE clrtab[][3]; |
36 |
> |
BYTE clrtab[256][3]; |
37 |
|
|
38 |
+ |
extern int samplefac; |
39 |
+ |
|
40 |
|
extern int getgifpix(); |
41 |
|
|
42 |
|
COLR *scanln; |
52 |
|
|
53 |
|
int bradj = 0; /* brightness adjustment */ |
54 |
|
|
55 |
+ |
int ncolors = 0; /* number of colors requested */ |
56 |
+ |
|
57 |
|
char *progname; |
58 |
|
|
59 |
|
|
61 |
|
int argc; |
62 |
|
char *argv[]; |
63 |
|
{ |
60 |
– |
int ncolors = 0; |
64 |
|
int bitsperpix; |
65 |
|
int i; |
66 |
|
#ifdef MSDOS |
70 |
|
setmode(fileno(stdout), O_BINARY); |
71 |
|
#endif |
72 |
|
progname = argv[0]; |
73 |
+ |
samplefac = 0; |
74 |
|
|
75 |
|
for (i = 1; i < argc; i++) |
76 |
|
if (argv[i][0] == '-') |
92 |
|
goto userr; |
93 |
|
bradj = atoi(argv[++i]); |
94 |
|
break; |
95 |
+ |
case 'n': |
96 |
+ |
samplefac = atoi(argv[++i]); |
97 |
+ |
break; |
98 |
|
default: |
99 |
|
goto userr; |
100 |
|
} |
143 |
|
exit(0); |
144 |
|
userr: |
145 |
|
fprintf(stderr, |
146 |
< |
"Usage: %s [-b][-c ncolors][-g gamv][-e +/-stops] input [output]\n", |
146 |
> |
"Usage: %s [-b][-d][-n samp][-c ncolors][-g gamv][-e +/-stops] input [output]\n", |
147 |
|
progname); |
148 |
|
exit(1); |
149 |
|
} |
162 |
|
if (freadcolrs(scanln, xmax, stdin) < 0) { |
163 |
|
fprintf(stderr, "%s: error reading picture (y==%d)\n", |
164 |
|
progname, ymax-1-y); |
165 |
+ |
exit(1); |
166 |
|
} |
167 |
|
while (++currow < y); |
168 |
|
if (bradj) |
169 |
|
shiftcolrs(scanln, xmax, bradj); |
170 |
|
colrs_gambs(scanln, xmax); |
171 |
|
if (pixscan != NULL) |
172 |
< |
dith_colrs(pixscan, scanln, xmax); |
172 |
> |
if (samplefac) |
173 |
> |
neu_dith_colrs(pixscan, scanln, xmax); |
174 |
> |
else |
175 |
> |
dith_colrs(pixscan, scanln, xmax); |
176 |
|
} |
177 |
|
|
178 |
|
|
181 |
|
{ |
182 |
|
register int i; |
183 |
|
|
184 |
< |
new_histo(); |
184 |
> |
if ((samplefac ? neu_init(xmax*ymax) : new_histo(xmax*ymax)) == -1) |
185 |
> |
goto memerr; |
186 |
|
for (i = 0; i < ymax; i++) { |
187 |
|
getrow(i); |
188 |
< |
cnt_colrs(scanln, xmax); |
188 |
> |
if (samplefac) |
189 |
> |
neu_colrs(scanln, xmax); |
190 |
> |
else |
191 |
> |
cnt_colrs(scanln, xmax); |
192 |
|
} |
193 |
< |
new_clrtab(nc); |
193 |
> |
if (samplefac) |
194 |
> |
neu_clrtab(nc); |
195 |
> |
else |
196 |
> |
new_clrtab(nc); |
197 |
|
for (i = 0; i < nc; i++) { |
198 |
|
rmap[i] = clrtab[i][RED]; |
199 |
|
gmap[i] = clrtab[i][GRN]; |
200 |
|
bmap[i] = clrtab[i][BLU]; |
201 |
|
} |
202 |
< |
if (dither && (pixscan = (BYTE *)malloc(xmax)) == NULL) { |
203 |
< |
fprintf(stderr, "%s: out of memory\n", progname); |
204 |
< |
exit(1); |
205 |
< |
} |
202 |
> |
if (dither && (pixscan = (BYTE *)malloc(xmax)) == NULL) |
203 |
> |
goto memerr; |
204 |
> |
return; |
205 |
> |
memerr: |
206 |
> |
fprintf(stderr, "%s: out of memory\n", progname); |
207 |
> |
exit(1); |
208 |
|
} |
209 |
|
|
210 |
|
|
229 |
|
|
230 |
|
getrow(y); |
231 |
|
if (greyscale) |
232 |
< |
return(normbright(scanln[x])); |
232 |
> |
return((normbright(scanln[x])*ncolors)>>8); |
233 |
|
if (pixscan != NULL) |
234 |
|
return(pixscan[x]); |
235 |
< |
return(map_pixel(scanln[x])); |
235 |
> |
return(samplefac ? neu_map_pixel(scanln[x]) : map_pixel(scanln[x])); |
236 |
|
} |
237 |
|
|
238 |
|
|