7 |
|
|
8 |
|
#include "copyright.h" |
9 |
|
|
10 |
+ |
#include <stdlib.h> |
11 |
|
#include "rtio.h" |
12 |
|
#include "rtmath.h" |
13 |
|
#include "normcodec.h" |
40 |
|
ncp->swapped = (nativebigendian() != rv); |
41 |
|
return 0; |
42 |
|
} |
43 |
+ |
if (!strncmp(s, "NCOMP=", 6)) { |
44 |
+ |
if (atoi(s+6) != 3) { |
45 |
+ |
if (ncp->hdrflags & HF_STDERR) { |
46 |
+ |
fputs(ncp->inpname, stderr); |
47 |
+ |
fputs(": NCOMP must equal 3\n", stderr); |
48 |
+ |
} |
49 |
+ |
return -1; |
50 |
+ |
} |
51 |
+ |
return 0; |
52 |
+ |
} |
53 |
+ |
if (!strncmp(s, "NROWS=", 6)) { |
54 |
+ |
ncp->res.yr = atoi(s+6); |
55 |
+ |
return 0; |
56 |
+ |
} |
57 |
+ |
if (!strncmp(s, "NCOLS=", 6)) { |
58 |
+ |
ncp->res.xr = atoi(s+6); |
59 |
+ |
return 0; |
60 |
+ |
} |
61 |
|
if (ncp->hdrflags & HF_HEADOUT) |
62 |
|
fputs(s, stdout); /* copy to standard output */ |
63 |
|
return 1; |
77 |
|
return 0; |
78 |
|
} |
79 |
|
/* get resolution string? */ |
80 |
< |
if (ncp->hdrflags & HF_RESIN && !fgetsresolu(&ncp->res, ncp->finp)) { |
80 |
> |
if (ncp->hdrflags & HF_RESIN && |
81 |
> |
(ncp->res.xr <= 0) | (ncp->res.yr <= 0) && |
82 |
> |
!fgetsresolu(&ncp->res, ncp->finp)) { |
83 |
|
if (ncp->hdrflags & HF_STDERR) { |
84 |
|
fputs(ncp->inpname, stderr); |
85 |
|
fputs(": bad resolution string\n", stderr); |
118 |
|
if (ncp->hdrflags & HF_RESOUT) /* put resolution string? */ |
119 |
|
fputsresolu(&ncp->res, stdout); |
120 |
|
|
121 |
< |
ncp->dstart = ncp->curpos = ftell(ncp->finp); |
121 |
> |
ncp->dstart = ftell(ncp->finp); |
122 |
|
return 1; |
123 |
|
} |
124 |
|
|
158 |
|
if (c == EOF && feof(ncp->finp)) |
159 |
|
return -1; |
160 |
|
|
140 |
– |
ncp->curpos += 4; |
141 |
– |
|
161 |
|
if (c == lastc) { /* optimization */ |
162 |
|
VCOPY(nrm, lastv); |
163 |
|
} else { |
175 |
|
int |
176 |
|
seek_nc_pix(NORMCODEC *ncp, int x, int y) |
177 |
|
{ |
159 |
– |
long seekpos; |
160 |
– |
|
178 |
|
if ((ncp->res.xr <= 0) | (ncp->res.yr <= 0)) { |
179 |
|
if (ncp->hdrflags & HF_STDERR) { |
180 |
|
fputs(progname, stderr); |
190 |
|
} |
191 |
|
return 0; |
192 |
|
} |
193 |
< |
seekpos = ncp->dstart + 4*((long)y*scanlen(&ncp->res) + x); |
194 |
< |
|
178 |
< |
if (seekpos != ncp->curpos && |
179 |
< |
fseek(ncp->finp, seekpos, SEEK_SET) == EOF) { |
193 |
> |
if (fseek(ncp->finp, ncp->dstart + 4*((long)y*scanlen(&ncp->res) + x), |
194 |
> |
SEEK_SET) == EOF) { |
195 |
|
if (ncp->hdrflags & HF_STDERR) { |
196 |
|
fputs(ncp->inpname, stderr); |
197 |
|
fputs(": seek error\n", stderr); |
198 |
|
} |
199 |
|
return -1; |
200 |
|
} |
186 |
– |
ncp->curpos = seekpos; |
201 |
|
return 1; |
202 |
|
} |
203 |
|
|