~ubuntu-branches/ubuntu/saucy/mricron/saucy

« back to all changes in this revision

Viewing changes to npm/nifti_img.pas

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-04-14 15:51:33 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110414155133-sd2umdatjqjlkhzt
Tags: 0.20110413.1~dfsg.1-1
* New upstream version. FSL BET related patches are no obsolete
  and have been removed. Mricron now performs autodetection of FSL.
  Additionally it supports a system-wide configuration file at
  /etc/mricron/mricron.ini
* Patch for older lazarus versions no longer applies to the lazarus
  version in unstable. Moved this patch into backport patch series files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
        lSmallIntP: SmallIntP;
28
28
        lV,lMin,lMax: single;
29
29
begin
30
 
 
31
30
        result := false;
 
31
 
32
32
        if (lStart >= lEnd) or (lStart < 1) or (lEnd < 1) then begin
33
33
                MainForm.NPMmsg('Error: LoadImg '+inttostr(lStart)+'>='+inttostr(lEnd)+' or zero');
34
34
                exit;
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];
 
120
            freemem(lByteP);
 
121
          end else if (lDataType = kDT_SIGNED_SHORT) then begin
 
122
            getmem(lSmallIntP, sizeof(smallint)* ((lEnd+1)-lStart));
 
123
            reset(lFdata,2);
 
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.');
 
126
            end;
 
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];
 
131
            freemem(lSmallIntP);
 
132
          end else if (lDataType = kDT_SIGNED_INT) or (lDataType = kDT_FLOAT) then begin
 
133
            //next: 4 byte data
 
134
            reset(lFdata,4);
 
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.');
 
137
            end;
 
138
            seek(lFdata,(lvox_offset div 4)+ (lStart-1) );
 
139
            BlockRead(lFdata, lImgData[lRApos], (lEnd+1)-lStart);
 
140
 
 
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]);
 
144
            end else begin
 
145
                for lInc := 1 to ((lEnd+1)-lStart) do
 
146
                    if specialsingle(lImgData^[lRApos+lInc-1]) then
 
147
                    lImgData^[lRApos+lInc-1] := 0;
 
148
            end;
 
149
          end else
 
150
              showmessage('Unsupported COMPRESSED data type '+inttostr(lDataType));
 
151
          closefile(lFdata);
 
152
        end; //not gz
 
153
        result := true;
 
154
end;
 
155
 
 
156
(*function LoadImgx(lInName: string; lImgData: SingleP; lStart, lEnd,linvox_offset,lRApos,lDataType,lVolVox: integer): boolean;
 
157
var
 
158
        lvox_offset,lInc,lFSize,lP2: integer;
 
159
        lFData: file;
 
160
        lImgName: string;
 
161
        lByteP: ByteP;
 
162
        lSmallIntP: SmallIntP;
 
163
        lV,lMin,lMax: single;
 
164
begin
 
165
 
 
166
        result := false;
 
167
        if (lStart >= lEnd) or (lStart < 1) or (lEnd < 1) then begin
 
168
                MainForm.NPMmsg('Error: LoadImg '+inttostr(lStart)+'>='+inttostr(lEnd)+' or zero');
 
169
                exit;
 
170
        end;
 
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');
 
176
                exit;
 
177
            end;
 
178
            lvox_offset := linvox_offset+ ((Vol4D(lInName)-1)* (lP2 * lVolVox));
 
179
        end else begin
 
180
            lImgName := lInName;
 
181
            lvox_offset := linvox_offset;
 
182
        end;
 
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));
 
188
                exit;
 
189
        end;
 
190
        filemode := 0;
 
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];
 
197
            freemem(lByteP);
 
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]);
 
205
            end;
 
206
            freemem(lByteP);
 
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));
 
210
 
 
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]);
 
217
            end;
 
218
            freemem(lByteP);}
 
219
            //test range
 
220
            {lINc := 1;
 
221
            lMin :=  lImgData^[lRApos+lInc-1];
 
222
            lMax := lMin;
 
223
            for lInc := 1 to ((lEnd+1)-lStart) do begin
 
224
                lV := lImgData^[lRApos+lInc-1];
 
225
                if lV > lMax then
 
226
                   lMax := lV;
 
227
                if lV < lMin then
 
228
                   lMin := lMax;
 
229
            end;
 
230
            MainForm.NPMmsg(inttostr(lvox_offset)+'  '+realtostr(lMin,8)+'  '+realtostr(lMax,8)); }
 
231
 
 
232
 
 
233
            //end
 
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]);
 
237
             end else begin
 
238
                for lInc := 1 to ((lEnd+1)-lStart) do
 
239
                    if specialsingle(lImgData^[lRApos+lInc-1])then
 
240
                    lImgData^[lRApos+lInc-1] := 0;
 
241
            end;
 
242
          end else begin
 
243
              showmessage(lImgName + ' is an unsupported compressed data type '+inttostr(lDataType));
 
244
              exit;
 
245
          end;
 
246
        end else begin
 
247
          assignfile(lFdata,lImgName);
 
248
          if lDataType = kDT_UNSIGNED_CHAR then begin
 
249
            getmem(lByteP, (lEnd+1)-lStart);
115
250
            reset(lFdata,1);
116
251
            seek(lFdata,lvox_offset+lStart-1);
117
252
            BlockRead(lFdata, lByteP^, (lEnd+1)-lStart);
151
286
          closefile(lFdata);
152
287
        end; //not gz
153
288
        result := true;
154
 
end;
 
289
end;  *)
155
290
 
156
291
function LoadImg8(lInName: string; lImgData: ByteP; lStart, lEnd,linvox_offset,lRApos,lDataType,lVolVox: integer): boolean;
157
292
//loads BINARY data - ignore scaling: zero or not zero