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