112
112
assignfile(lFdata,lImgName);
113
113
if lDataType = kDT_UNSIGNED_CHAR then begin
114
114
getmem(lByteP, (lEnd+1)-lStart);
115
reset(lFdata,1); //12/2010
116
seek(lFdata,lvox_offset+lStart-1);
117
BlockRead(lFdata, lByteP^, (lEnd+1)-lStart);
118
for lInc := 1 to ((lEnd+1)-lStart) do
119
lImgData^[lRApos+lInc-1] := lByteP^[lInc];
121
end else if (lDataType = kDT_SIGNED_SHORT) then begin
122
getmem(lSmallIntP, sizeof(smallint)* ((lEnd+1)-lStart));
124
if (lvox_offset mod 2) <> 0 then begin
125
showmessage('Error: this software can only read headers with dataoffsets that are divisible by 4.');
127
seek(lFdata,(lvox_offset div 2)+ (lStart-1));
128
BlockRead(lFdata, lSmallIntP^, (lEnd+1)-lStart);
129
for lInc := 1 to ((lEnd+1)-lStart) do
130
lImgData^[lRApos+lInc-1] := lSmallIntP^[lInc];
132
end else if (lDataType = kDT_SIGNED_INT) or (lDataType = kDT_FLOAT) then begin
135
if (lvox_offset mod 4) <> 0 then begin
136
showmessage('Error: this software can only read headers with dataoffsets that are divisible by 4.');
138
seek(lFdata,(lvox_offset div 4)+ (lStart-1) );
139
BlockRead(lFdata, lImgData[lRApos], (lEnd+1)-lStart);
141
if lDataType = kDT_SIGNED_INT then begin
142
for lInc := 1 to ((lEnd+1)-lStart) do
143
lImgData^[lRApos+lInc-1] := conv4r4i (lImgData^[lRApos+lInc-1]);
145
for lInc := 1 to ((lEnd+1)-lStart) do
146
if specialsingle(lImgData^[lRApos+lInc-1]) then
147
lImgData^[lRApos+lInc-1] := 0;
150
showmessage('Unsupported COMPRESSED data type '+inttostr(lDataType));
156
(*function LoadImgx(lInName: string; lImgData: SingleP; lStart, lEnd,linvox_offset,lRApos,lDataType,lVolVox: integer): boolean;
158
lvox_offset,lInc,lFSize,lP2: integer;
162
lSmallIntP: SmallIntP;
163
lV,lMin,lMax: single;
167
if (lStart >= lEnd) or (lStart < 1) or (lEnd < 1) then begin
168
MainForm.NPMmsg('Error: LoadImg '+inttostr(lStart)+'>='+inttostr(lEnd)+' or zero');
171
if Files4D(lInName) then begin
172
lImgName := Filename4D(lInName);
173
lP2 := BPP (lDataType);
174
if lP2 = 0 then begin
175
Showmessage(lImgName +' is an unsupported file type');
178
lvox_offset := linvox_offset+ ((Vol4D(lInName)-1)* (lP2 * lVolVox));
181
lvox_offset := linvox_offset;
183
if UpCaseExt(lImgName) = '.HDR' then
184
lImgName := changefileext(lImgName,'.img');
185
lFSize := FSize(lImgName);
186
if (not GzExt(lImgName)) and (lFSize < (lEnd+ lvox_offset)) then begin
187
MainForm.NPMmsg('Error: LoadImg '+lImgName+' FSize = '+inttostr(lFSize)+' Expected '+inttostr(lEnd+ lvox_offset));
191
if GzExt(lImgName) then begin
192
if lDataType = kDT_UNSIGNED_CHAR then begin
193
getmem(lByteP, (lEnd+1)-lStart);
194
UnGZip(lImgName,lByteP,lvox_offset+lStart-1,(lEnd+1)-lStart);
195
for lInc := 1 to ((lEnd+1)-lStart) do
196
lImgData^[lRApos+lInc-1] := lByteP^[lInc];
198
end else if (lDataType = kDT_SIGNED_SHORT) then begin
199
//getmem(lSmallIntP, sizeof(smallint)* ((lEnd+1)-lStart));
200
getmem(lByteP, ((lEnd+1)-lStart)*sizeof(smallint));
201
UnGZip(lImgName,lByteP,lvox_offset+((lStart-1)*sizeof(smallint)),((lEnd+1)-lStart)*sizeof(smallint));
202
for lInc := 1 to ((lEnd+1)-lStart) do begin
203
lP2 := ((lInc-1)*2)+1 ;
204
lImgData^[lRApos+lInc-1] := makesmallint(lByteP^[lP2],lByteP^[lP2+1]);
207
end else if (lDataType = kDT_SIGNED_INT) or (lDataType = kDT_FLOAT) then begin
208
lByteP := ByteP(@lImgData^[lRApos]);
209
UnGZip(lImgName,lByteP,lvox_offset+((lStart-1)*sizeof(single)),((lEnd+1)-lStart)*sizeof(single));
211
{getmem(lByteP, ((lEnd+1)-lStart)*sizeof(single));
212
UnGZip(lImgName,lByteP,lvox_offset+((lStart-1)*sizeof(single)),((lEnd+1)-lStart)*sizeof(single));
213
for lInc := 1 to ((lEnd+1)-lStart) do begin
214
lP2 := ((lInc-1)*4)+1 ;
215
lImgData^[lRApos+lInc-1] := makesingle(lByteP^[lP2],lByteP^[lP2+1],lByteP^[lP2+2],lByteP^[lP2+3]);
216
//lImgData^[lRApos+lInc-1] := makesingle(lByteP^[lP2+3],lByteP^[lP2+2],lByteP^[lP2+1],lByteP^[lP2]);
221
lMin := lImgData^[lRApos+lInc-1];
223
for lInc := 1 to ((lEnd+1)-lStart) do begin
224
lV := lImgData^[lRApos+lInc-1];
230
MainForm.NPMmsg(inttostr(lvox_offset)+' '+realtostr(lMin,8)+' '+realtostr(lMax,8)); }
234
if lDataType = kDT_SIGNED_INT then begin
235
for lInc := 1 to ((lEnd+1)-lStart) do
236
lImgData^[lRApos+lInc-1] := conv4r4i (lImgData^[lRApos+lInc-1]);
238
for lInc := 1 to ((lEnd+1)-lStart) do
239
if specialsingle(lImgData^[lRApos+lInc-1])then
240
lImgData^[lRApos+lInc-1] := 0;
243
showmessage(lImgName + ' is an unsupported compressed data type '+inttostr(lDataType));
247
assignfile(lFdata,lImgName);
248
if lDataType = kDT_UNSIGNED_CHAR then begin
249
getmem(lByteP, (lEnd+1)-lStart);
116
251
seek(lFdata,lvox_offset+lStart-1);
117
252
BlockRead(lFdata, lByteP^, (lEnd+1)-lStart);