14 |
|
|
15 |
|
#include "color.h" |
16 |
|
|
17 |
+ |
#include "resolu.h" |
18 |
+ |
|
19 |
|
#include "data.h" |
20 |
|
|
21 |
|
|
22 |
|
extern char *fgetword(); |
21 |
– |
extern double atof(); |
23 |
|
|
24 |
|
extern char *libpath; /* library search path */ |
25 |
|
|
158 |
|
char *pfname; |
159 |
|
FILE *fp; |
160 |
|
COLOR *scanin; |
161 |
< |
int width, height; |
162 |
< |
int x, y; |
163 |
< |
register int i; |
161 |
> |
int sl, ns; |
162 |
> |
RESOLU inpres; |
163 |
> |
FLOAT loc[2]; |
164 |
> |
int y; |
165 |
> |
register int x, i; |
166 |
|
register DATARRAY *pp; |
167 |
|
/* look for array in list */ |
168 |
|
for (pp = plist; pp != NULL; pp = pp->next) |
187 |
|
/* get dimensions */ |
188 |
|
inpaspect = 1.0; |
189 |
|
getheader(fp, headaspect); |
190 |
< |
if (fgetresolu(&width, &height, fp) != (YMAJOR|YDECR)) |
190 |
> |
if (!fgetsresolu(&inpres, fp)) |
191 |
|
goto readerr; |
192 |
|
for (i = 0; i < 3; i++) { |
193 |
|
pp[i].nd = 2; |
194 |
< |
pp[i].dim[0].ne = height; |
195 |
< |
pp[i].dim[1].ne = width; |
194 |
> |
pp[i].dim[0].ne = inpres.yr; |
195 |
> |
pp[i].dim[1].ne = inpres.xr; |
196 |
|
pp[i].dim[0].org = |
197 |
|
pp[i].dim[1].org = 0.0; |
198 |
< |
if (width <= height*inpaspect) { |
199 |
< |
pp[i].dim[0].siz = inpaspect*(double)height/width; |
198 |
> |
if (inpres.xr <= inpres.yr*inpaspect) { |
199 |
> |
pp[i].dim[0].siz = inpaspect * |
200 |
> |
(double)inpres.yr/inpres.xr; |
201 |
|
pp[i].dim[1].siz = 1.0; |
202 |
|
} else { |
203 |
|
pp[i].dim[0].siz = 1.0; |
204 |
< |
pp[i].dim[1].siz = (double)width/height/inpaspect; |
204 |
> |
pp[i].dim[1].siz = (double)inpres.xr/inpres.yr / |
205 |
> |
inpaspect; |
206 |
|
} |
207 |
|
pp[i].dim[0].p = pp[i].dim[1].p = NULL; |
208 |
< |
pp[i].arr = (DATATYPE *)malloc(width*height*sizeof(DATATYPE)); |
208 |
> |
pp[i].arr = (DATATYPE *) |
209 |
> |
malloc(inpres.xr*inpres.yr*sizeof(DATATYPE)); |
210 |
|
if (pp[i].arr == NULL) |
211 |
|
goto memerr; |
212 |
|
} |
213 |
|
/* load picture */ |
214 |
< |
if ((scanin = (COLOR *)malloc(width*sizeof(COLOR))) == NULL) |
214 |
> |
sl = scanlen(&inpres); |
215 |
> |
ns = numscans(&inpres); |
216 |
> |
if ((scanin = (COLOR *)malloc(sl*sizeof(COLOR))) == NULL) |
217 |
|
goto memerr; |
218 |
< |
for (y = height-1; y >= 0; y--) { |
219 |
< |
if (freadscan(scanin, width, fp) < 0) |
218 |
> |
for (y = 0; y < ns; y++) { |
219 |
> |
if (freadscan(scanin, sl, fp) < 0) |
220 |
|
goto readerr; |
221 |
< |
for (x = 0; x < width; x++) |
222 |
< |
for (i = 0; i < 3; i++) |
223 |
< |
pp[i].arr[y*width+x] = colval(scanin[x],i); |
221 |
> |
for (x = 0; x < sl; x++) { |
222 |
> |
pix2loc(loc, &inpres, x, y); |
223 |
> |
i = (int)(loc[1]*inpres.yr)*inpres.xr + |
224 |
> |
(int)(loc[0]*inpres.xr); |
225 |
> |
pp[0].arr[i] = colval(scanin[x],RED); |
226 |
> |
pp[1].arr[i] = colval(scanin[x],GRN); |
227 |
> |
pp[2].arr[i] = colval(scanin[x],BLU); |
228 |
> |
} |
229 |
|
} |
230 |
|
free((char *)scanin); |
231 |
|
fclose(fp); |