1 function [HDR,data] =
iopen(HDR,PERMISSION,CHAN,MODE,arg5,arg6)
2 % IOPEN opens image files
for reading and writing and returns
3 % the header information. Many different IMAGE formats are supported.
5 % HDR =
iopen(Filename, PERMISSION, [, CHAN [, MODE]]);
7 % PERMISSION is one of the following strings
11 % HDR contains the Headerinformation and
internal data
13 % see also: SLOAD, SREAD, SSEEK, STELL, SCLOSE, SWRITE, SEOF
16 % This program is free software; you can redistribute it and/or
17 % modify it under the terms of the GNU General Public License
18 % as published by the Free Software Foundation; either version 3
19 % of the License, or (at your option) any later version.
21 % $Id:
iopen.m 2205 2009-10-27 12:18:15Z schloegl $
22 % (C) 2005,2007,2008 by Alois Schloegl <a.schloegl@ieee.org>
23 % This is part of the BIOSIG-toolbox http:
29 elseif ischar(HDR) & exist(HDR)==2,
36 elseif strcmp(HDR.TYPE,
'IMAGE:BMP'),
37 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,
'b'],
'ieee-le');
38 fseek(HDR.FILE.FID,10,-1);
40 tmp = fread(HDR.FILE.FID,4,
'uint32');
42 HDR.BMP.sizeBitmapInfoHeader = tmp(2);
43 HDR.IMAGE.Size = tmp(3:4)
';
45 tmp = fread(HDR.FILE.FID,2,'uint16
');
46 HDR.BMP.biPlanes = tmp(1);
49 tmp = fread(HDR.FILE.FID,6,'uint32
');
50 HDR.BMP.biCompression = tmp(1);
51 HDR.BMP.biImageSize = tmp(2);
52 HDR.BMP.biXPelsPerMeter = tmp(3);
53 HDR.BMP.biYPelsPerMeter = tmp(4);
54 HDR.BMP.biColorUsed = tmp(5);
55 HDR.BMP.biColorImportant = tmp(6);
59 elseif strcmp(HDR.TYPE,'IMAGE:FITS
'),
60 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,'b
'],'ieee-be
');
63 HDR.HeadLen = ftell(HDR.FILE.FID);
65 cpl = 80; % char's per line
66 while (HDR.FILE.size > HDR.HeadLen(max(KK,1))+BlockSize),
71 [tmp,c] = fread(HDR.FILE.FID,[cpl,36],
'uchar');
73 fprintf(HDR.FILE.stderr,
'Warning IOPEN: incomplete block\n');
76 % [FLAG.END,ftell(HDR.FILE.FID),size(data)],
77 for k = 1:size(data,1),
79 if strncmp(s,'COMMENT
',7);
81 elseif strncmp(s,'HISTORY
',7);
83 elseif all(s(9:10)=='=
');
84 len = min([cpl,find(s=='/
')-1]);
85 [key, t] = strtok(s, '=
');
87 if s(11)==char(39), % string
88 [val, t] = strtok(s(11:len),char(39));
89 HDR.FITS{KK} = setfield(HDR.FITS{KK},key,val);
90 elseif any(s(30)=='TF
'), % logical
91 HDR.FITS{KK} = setfield(HDR.FITS{KK},key,s(30)=='T
');
92 elseif all(s(11:len)==' '), % empty
93 HDR.FITS{KK} = setfield(HDR.FITS{KK},key,[]);
94 elseif all(s(11:len)=='(
'), % complex
95 [val,status] = str2double(s(11:len),[],'(,)
');
96 HDR.FITS{KK} = setfield(HDR.FITS{KK},key,val(1)+i*val(2));
98 [val,status] = str2double(s(11:len));
101 [val,status] = str2double(s(11:len));
104 fprintf(2,'Warning SOPEN (FITS): Expected numerical value - found string \n\t%s: %s\n
',key,s(11:len));
105 HDR.FITS{KK} = setfield(HDR.FITS{KK},key,s(11:len));
107 HDR.FITS{KK} = setfield(HDR.FITS{KK},key,val);
111 elseif strncmp(s,'END
',3)
114 %elseif strncmp(s,' ',8),
117 % fprintf(2,'ERROR SOPEN (FITS):
"%s"\n
',s);
122 HDR.HeadLen(KK) = ftell(HDR.FILE.FID);
123 HDR.IMAGE(KK).Size = [0,0];
125 for k = 1:HDR.FITS{KK}.NAXIS,
126 HDR.IMAGE(KK).Size(k) = getfield(HDR.FITS{KK},['NAXIS
',int2str(k)]);
128 HDR.IMAGE_Size(KK) = prod(HDR.IMAGE(KK).Size);
130 HDR.GDFTYP = ['uint
',num2str(HDR.FITS{1}.BITPIX)];
132 % data = fread(HDR.FILE.FID,prod(HDR.IMAGE.Size),HDR.GDFTYP);
133 % data = reshape(data,HDR.IMAGE.Size); % * HDR.Cal + HDR.Off;
135 BlockSize = ceil(prod(HDR.IMAGE(KK).Size)*abs(HDR.FITS{KK}.BITPIX)/(8*36*cpl))*cpl*36;
136 fseek(HDR.FILE.FID,BlockSize,'cof
');
139 % fclose(HDR.FILE.FID);
143 elseif strcmp(HDR.TYPE,'IMAGE:IFS
'), % Ultrasound file format
144 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,'b
'],'ieee-le
');
146 hdr = fread(HDR.FILE.FID,[1,HDR.HeadLen],'uchar
');
147 HDR.Date = char(hdr(77:100));
148 tmp = char(hdr(213:220));
149 if strncmp(tmp,'32flt
',5)
150 HDR.GDFTYP = 'float32
';
151 elseif strncmp(tmp,'u8bit
',5)
152 HDR.GDFTYP = 'uint8
';
156 fclose(HDR.FILE.FID);
159 elseif strcmp(HDR.TYPE,'IMAGE:EXIF
') | strncmp(HDR.TYPE,'IMAGE:JPG
',9),
160 GDFTYP = {'uint8
','char
','uint16
','uint32
','2*uint32
','int8
','uint8
','int16
','int32
','2*int32
','float32
','float64
'};
161 GDFTYP = {'uint8
','char
','uint16
','uint32
','uint64
','int8
','uint8
','int16
','int32
','int64
','float32
','float64
'};
162 size0 = [1,1,2,4,8,1,1,2,4,8,4,8];
166 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,'b
'],HDR.Endianity);
167 tag = fread(HDR.FILE.FID,[1],'uint16
');
168 if tag == hex2dec('FFD8
'), % compressed: JPEG or EXIF
170 POS = ftell(HDR.FILE.FID);
171 tag = fread(HDR.FILE.FID,1,'uint16
');
172 LEN = fread(HDR.FILE.FID,1,'uint16
');
173 while ftell(HDR.FILE.FID)<HDR.FILE.size,
175 elseif (tag == hex2dec('8298
')) % image data
176 HDR.EXIF.Copyright = fread(HDR.FILE.FID,LEN-2,'uint8
');
177 elseif (tag == hex2dec('F9FE
')) % image data
178 HDR.data.compressed = fread(HDR.FILE.FID,LEN-2,'uint8
');
179 elseif (tag == hex2dec('FEFA
')) % JPEG field: (thumbnail?)
180 HDR.JPEG.FEFA = fread(HDR.FILE.FID,LEN-2,'uint8
');
181 elseif (tag == hex2dec('FF00
')) % JPEG field: (thumbnail?)
182 HDR.JPEG.FF00 = fread(HDR.FILE.FID,LEN-2,'uint8
');
183 elseif (tag == hex2dec('FFC0
')) % JPEG field: start of frame
184 HDR.JPEG.BITS = fread(HDR.FILE.FID,1,'uint8
');
185 HDR.IMAGE.Size= fread(HDR.FILE.FID,[1,2],'uint16
');
186 HDR.JPEG.SOF = fread(HDR.FILE.FID,10,'uint8
');
187 elseif (tag == hex2dec('FFD9
')) % JPEG field: end of data
189 elseif (tag == hex2dec('FFC4
')) % JPEG field:
190 tmp = fread(HDR.FILE.FID,LEN-2,'uint8
');
191 if isfield(HDR.JPEG,'C4
');
192 HDR.JPEG.C4{length(HDR.JPEG.C4)+1}=tmp;
194 HDR.JPEG.C4{1} = tmp;
196 elseif (tag == hex2dec('FFDA
')) % JPEG field: start of scan
197 HDR.JPEG.SOS = fread(HDR.FILE.FID,10,'uint8
');
198 elseif (tag == hex2dec('FFDB
')) % EXIF field: Quantization Table
199 tmp = fread(HDR.FILE.FID,[65,3],'uint8
');
200 if isfield(HDR.JPEG,'DQT
');
201 HDR.JPEG.DQT{length(HDR.JPEG.DQT)+1}=tmp;
203 HDR.JPEG.DQT{1} = tmp;
206 elseif (tag == hex2dec('FFDD
')) % EXIF field:
207 HDR.EXIF.DRI = fread(HDR.FILE.FID,1,'uint16
');
208 elseif (tag == hex2dec('FFE0
')) % JPEG
209 HDR.JPEG.E0 = fread(HDR.FILE.FID,LEN-2,'uint8
');
210 elseif (tag == hex2dec('FFE1
')) % EXIF field: APP1
211 tmp = fread(HDR.FILE.FID,[1,6],'uint8
');
212 if ~strncmp(char(tmp),'Exif
',4)
213 fprintf(HDR.FILE.stderr,'Warning EXIF: tag FFE1 is not EXIF but %s\n
',char(tmp));
215 pos = ftell(HDR.FILE.FID);
216 s = fread(HDR.FILE.FID,[1,4],'uint8
');
217 if all(s(1:4)==[73,73,42,0]);
219 H.Endianity = 'ieee-le
';
221 elseif all(s(1:4)==[77,77,0,42]);
223 H.Endianity = 'ieee-be
';
226 fprintf(HDR.FILE.stderr,'Warning EXIF: invalid TIFF tag %s\n
',char(s));
228 if ~strcmp(HDR.Endianity,H.Endianity)
229 % {HDR.Endianity;H.Endianity}
230 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,'b
'],H.Endianity);
231 fseek(HDR.FILE.FID,pos+4,'bof
');
235 offset.IFD0 = fread(HDR.FILE.FID,1,'uint32
');
236 fseek(HDR.FILE.FID, pos+offset.IFD0, 'bof
');
237 nf = fread(HDR.FILE.FID,1,'uint16
');
239 fprintf(HDR.FILE.stderr,'Warning EXIF: %i instead of 11 %i tags.\n
',nf);
240 % if nf>11, return; end;
244 tmp = fread(HDR.FILE.FID,2,'uint16
');
247 tmp = fread(HDR.FILE.FID,1,'uint32
');
249 if count(k)*size0(typ(k))>4
250 valoffset(k) = fread(HDR.FILE.FID,1,'uint32
');
252 tmp = fread(HDR.FILE.FID,4/size0(typ(k)),GDFTYP{typ(k)});
253 VAL{k} = tmp(1:count(k));
256 len = fread(HDR.FILE.FID,1,'uint16
'); % jump to next IFD
257 if len>0, LEN = len; end;
258 HDR.EXIF.ResolutionUnit = 2; % default value
260 if count(k)*size0(typ(k))>4
261 fseek(HDR.FILE.FID,pos+valoffset(k),'bof
');
263 tmp = fread(HDR.FILE.FID,[count(k),2],'int32
');
264 tmp = tmp(:,1)./tmp(:,2);
266 tmp = fread(HDR.FILE.FID,count(k),GDFTYP{typ(k)});
272 HDR.EXIF.ImageDesc = char(tmp(:)');
274 HDR.EXIF.Make = char(tmp(:)
');
276 HDR.EXIF.Model = char(tmp(:)');
278 HDR.EXIF.Orientation = tmp
';
280 HDR.EXIF.XResolution = tmp;
282 HDR.EXIF.YResolution = tmp;
284 HDR.EXIF.Orientation = tmp;
287 HDR.EXIF.ResolutionUnit = 'inch
';
289 HDR.EXIF.ResolutionUnit = 'cm
';
292 HDR.EXIF.SoftwareVersion = char(tmp');
294 HDR.EXIF.Date = char(tmp
');
295 HDR.T0 = str2double(HDR.EXIF.Date,':
');
297 HDR.EXIF.YCbCrPositioning = tmp;
298 elseif tagid(k)==33432
299 HDR.EXIF.Copyright = char(tmp');
300 elseif tagid(k)==34665
301 HDR.EXIF.IFDPointer = tmp;
302 elseif tagid(k)==34853
303 HDR.EXIF.GPS_IFDPointer = tmp;
304 elseif tagid(k)==40965
305 HDR.EXIF.Interoperability_IFDPointer = tmp;
307 elseif tagid(k)==41985
308 HDR.EXIF.CostumRendered = tmp;
309 elseif tagid(k)==41986
310 HDR.EXIF.ExposureMode = tmp;
311 elseif tagid(k)==41987
312 HDR.EXIF.WhiteBalance = tmp;
313 elseif tagid(k)==41988
314 HDR.EXIF.DigitalZoomratio = tmp;
315 elseif tagid(k)==41989
316 HDR.EXIF.FocalLengthIn35mmFilm = tmp;
317 elseif tagid(k)==41990
318 HDR.EXIF.SceneCaptureType = tmp;
319 elseif tagid(k)==41991
320 HDR.EXIF.GainControl = tmp;
321 elseif tagid(k)==41992
322 HDR.EXIF.Contrast = tmp;
323 elseif tagid(k)==41993
324 HDR.EXIF.Saturation = tmp;
325 elseif tagid(k)==41994
326 HDR.EXIF.Sharpness = tmp;
327 elseif tagid(k)==41995
328 HDR.EXIF.DeviceSettingDescription = tmp;
329 elseif tagid(k)==41996
330 HDR.EXIF.SubjectDistanceRange = tmp;
331 elseif tagid(k)==42016
332 HDR.EXIF.imageUniqueID = tmp;
334 elseif tagid(k)==hex2dec(
'c4a5')
335 HDR.EXIF.c4a5 = tmp';
341 if ~strcmp(HDR.Endianity,H.Endianity)
342 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,'b'],HDR.Endianity);
344 %HDR.EXIF.APP1 = fread(HDR.FILE.FID,LEN-2-6-4,'uint8');
345 elseif (tag == hex2dec('FFE2')) % EXIF field: APP2
346 HDR.EXIF.APP2 = fread(HDR.FILE.FID,LEN-2,'uint8')';
347 elseif (tag == hex2dec('FFE3')) % EXIF field: APP3
348 HDR.EXIF.APP3 = fread(HDR.FILE.FID,LEN-2,'uint8')';
350 elseif (tag == hex2dec('FFEC')) % JPEG
351 tmp =
char(fread(HDR.FILE.FID,[1,LEN-2],'uint8'));
352 if isfield(HDR.JPEG,'EC');
353 HDR.JPEG.EC{length(HDR.JPEG.EC)+1}=tmp;
355 HDR.JPEG.EC{1} = tmp;
357 elseif (tag == hex2dec(
'FFED')) % JPEG
358 tmp = char(fread(HDR.FILE.FID,[1,LEN-2],
'uint8'));
359 if isfield(HDR.JPEG,
'ED');
360 HDR.JPEG.ED{length(HDR.JPEG.ED)+1}=tmp;
362 HDR.JPEG.ED{1} = tmp;
364 elseif (tag == hex2dec(
'FFFD')) % JPEG
365 tmp = char(fread(HDR.FILE.FID,[1,LEN-2],
'uint8'));
366 if isfield(HDR.JPEG,
'FD');
367 HDR.JPEG.FD{length(HDR.JPEG.FD)+1}=tmp;
369 HDR.JPEG.FD{1} = tmp;
371 elseif (tag == hex2dec(
'FFEE')) % JPEG
372 tmp = char(fread(HDR.FILE.FID,[1,LEN-2],
'uint8'));
373 if isfield(HDR.JPEG,
'EE');
374 HDR.JPEG.EE{length(HDR.JPEG.EE)+1}=tmp;
376 HDR.JPEG.EE{1} = tmp;
378 elseif (tag == hex2dec(
'FFFE')) % JPEG
379 tmp = char(fread(HDR.FILE.FID,[1,LEN-2],
'uint8'));
380 if isfield(HDR.JPEG,
'FE');
381 HDR.JPEG.FE{length(HDR.JPEG.FE)+1}=tmp;
383 HDR.JPEG.FE{1} = tmp;
385 elseif 1, %tag>=15/16*2^16;
386 %fprintf(1,
'%5i\t%4x\t%5i\n',LEN,tag,tag);
388 fprintf(1,
'%5i\t%4x\t%5i\n',LEN,tag,tag);
390 fseek(HDR.FILE.FID,POS+LEN+2,
'bof');
391 POS = ftell(HDR.FILE.FID);
392 tag = fread(HDR.FILE.FID,1,
'uint16');
393 LEN = fread(HDR.FILE.FID,1,
'uint16');
396 fclose(HDR.FILE.FID);
399 elseif strcmp(HDR.TYPE,
'IMAGE:HGT'),
401 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,
''],
'ieee-be');
402 HDR.IMAGE.Size = [1,1] * sqrt(HDR.FILE.size/2);
407 elseif strcmp(HDR.TYPE,
'IMAGE:JPG'),
408 GDFTYP = {
'uint8',
'char',
'uint16',
'uint32',
'2*uint32',
'int8',
'uint8',
'int16',
'int32',
'2*int32',
'float32',
'float64'};
409 GDFTYP = {
'uint8',
'char',
'uint16',
'uint32',
'uint64',
'int8',
'uint8',
'int16',
'int32',
'int64',
'float32',
'float64'};
411 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,
'b'],
'ieee-le');
412 HDR.JPEG.H1 = fread(HDR.FILE.FID,[1,8],
'uchar');
415 TAG = fread(HDR.FILE.FID,1,
'uint16');
416 type = fread(HDR.FILE.FID,1,
'uint16');
417 count = fread(HDR.FILE.FID,1,
'uint32');
418 offset = fread(HDR.FILE.FID,1,
'uint32');
421 fclose(HDR.FILE.FID);
425 elseif strcmp(HDR.TYPE,
'IMAGE:PCX'),
427 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,
'b'],
'ieee-le');
428 tmp = fread(HDR.FILE.FID,[1,4],
'uchar');
429 HDR.PCX.Version = tmp(2);
431 axis_size = fread(HDR.FILE.FID,[1,6],
'uint16');
432 HDR.IMAGE.Size = axis_size([3:4])-axis_size([1:2]);
433 HDR.PCX.dpi = axis_size(5:6);
434 LUT = fread(HDR.FILE.FID,[1,48],
'uint8');
435 tmp = fread(HDR.FILE.FID,[5],
'uint16');
436 HDR.PCX.Nplanes = tmp(1);
439 fseek(HDR.FILE.FID,3*256,
'eof');
440 HDR.IMAGE.Palette = fread(HDR.FILE.FID,[256,3],
'uint8');
443 fseek(HDR.FILE.FID,128,
'bof');
446 fclose(HDR.FILE.FID);
450 elseif strcmp(HDR.TYPE,
'IMAGE:PBMA') | strcmp(HDR.TYPE,
'IMAGE:PGMA') | strcmp(HDR.TYPE,
'IMAGE:PPMA') ,
451 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,
't'],
'ieee-le');
456 HDR.IMAGE.Size = [inf,inf];
458 while ~feof(HDR.FILE.FID) & (length(data)<prod(HDR.IMAGE.Size))
459 line = fgetl(HDR.FILE.FID);
462 elseif strncmp(line,
'P1',2),
464 elseif strncmp(line,
'P2',2),
466 elseif strncmp(line,
'P3',2),
469 elseif isnumeric(line),
473 HDR.IMAGE.Size = tmp;
475 error(
'IOPEN (PPMA)');
482 line = line(1:min([find(line==
'#'),length(line)])); % remove comment
483 [tmp,status] =
str2double(
char(line)); %,[],[9,10,13,32])
489 fclose(HDR.FILE.FID);
491 if strcmp(HDR.TYPE,'IMAGE:PPMA
'),
492 if prod(HDR.IMAGE.Size)*3~=length(s),
493 fprintf(HDR.FILE.stderr,'SLOAD(P3): %i * %i != %i \n
',HDR.IMAGE.Size,length(s));
495 data = repmat(NaN,[HDR.IMAGE.Size,3]);
496 data(:,:,1) = reshape(s(1:3:end),HDR.IMAGE.Size)';
497 data(:,:,2) = reshape(s(2:3:end),HDR.IMAGE.Size)
';
498 data(:,:,3) = reshape(s(3:3:end),HDR.IMAGE.Size)';
501 if prod(HDR.IMAGE.Size)~=length(s),
502 fprintf(HDR.FILE.stderr,
'SLOAD(P1/P2): %i * %i != %i \n',HDR.IMAGE.Size,length(s));
504 data = reshape(s,HDR.IMAGE.Size)
';
509 elseif strcmp(HDR.TYPE,'IMAGE:PBMB
'),
510 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,'b
'],'ieee-le
');
511 status = fseek(HDR.FILE.FID, HDR.HeadLen, 'bof
');
512 [tmp,count] = fread(HDR.FILE.FID,[HDR.IMAGE.Size(2)/8,HDR.IMAGE.Size(1)],'uint8
');
513 fclose(HDR.FILE.FID);
515 data = zeros(HDR.IMAGE.Size)';
518 data(:,k:8:HDR.IMAGE.Size(1)) = bitand(tmp
',2^(8-k))>0;
521 elseif strcmp(HDR.TYPE,'IMAGE:PGMB
'),
522 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,'b
'],'ieee-le
');
523 status = fseek(HDR.FILE.FID, HDR.HeadLen, 'bof
');
524 [data,count] = fread(HDR.FILE.FID,HDR.IMAGE.Size,'uint8
');
525 fclose(HDR.FILE.FID);
528 elseif strcmp(HDR.TYPE,
'IMAGE:PPMB'),
529 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,
'b'],
'ieee-le');
530 status = fseek(HDR.FILE.FID, HDR.HeadLen,
'bof');
531 [tmp,count] = fread(HDR.FILE.FID,[3*HDR.IMAGE.Size(1),HDR.IMAGE.Size(2)],
'uint8');
532 fclose(HDR.FILE.FID);
534 data = zeros([HDR.IMAGE.Size([2,1]),3]);
535 data(:,:,1) = tmp(1:3:end,:)
';
536 data(:,:,2) = tmp(2:3:end,:)';
537 data(:,:,3) = tmp(3:3:end,:)
';
540 elseif strcmp(HDR.TYPE,'IMAGE:TIFF
'),
541 GDFTYP = {'uint8
','char','uint16
','uint32
','2*uint32
','int8
','uint8
','int16
','int32
','2*int32
','float32
','float64
'};
542 GDFTYP = {'uint8
','char','uint16
','uint32
','uint32
','int8
','uint8
','int16
','int32
','int32
','float32
','float64
'};
543 GDFTYP{16} = 'uint64
';
544 GDFTYP{17} = 'int64
';
545 SIZEOF = [1,1,2,4,8,1,1,2,4,8,4,8,0,0,0,8,8,8];
547 if ~HDR.FLAG.BigTIFF,
548 NIFD_TYPE = 'uint16
';
551 NIFD_TYPE = 'uint64
';
556 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,'b
'],HDR.Endianity);
558 [tmp,c] = fread(HDR.FILE.FID,2,IFD_TYPE);
562 HDR.TIFF.Compression = 1;
567 status = fseek(HDR.FILE.FID, OFFSET, 'bof
');
568 [NIFD,c] = fread(HDR.FILE.FID,1,NIFD_TYPE);
570 POS = ftell(HDR.FILE.FID);
571 [tmp,c] = fread(HDR.FILE.FID,2,'uint16
');
575 [COUNT,c] = fread(HDR.FILE.FID,1,IFD_TYPE);
577 FLAG = any(TYP==[1:12,16:17]);
579 if (COUNT * SIZEOF(TYP)) > 4+4*HDR.FLAG.BigTIFF,
580 [OFFSET, c] = fread(HDR.FILE.FID, 1, IFD_TYPE);
581 status = fseek(HDR.FILE.FID, OFFSET, 'bof
');
584 [VALUE,c] = fread(HDR.FILE.FID, [2,COUNT], GDFTYP{TYP});
585 VALUE = VALUE(1,:)./VALUE(2,:);
587 [VALUE,c] = fread(HDR.FILE.FID, [1,COUNT], GDFTYP{TYP});
588 if TAG==2, VALUE=char(VALUE); end;
596 HDR.TIFF.NewSubFileType = VALUE;
598 HDR.TIFF.SubFileType = VALUE;
600 HDR.IMAGE.Size(2) = VALUE;
602 HDR.IMAGE.Size(1) = VALUE;
604 HDR.Bits = VALUE(:)';
605 HDR.IMAGE.Size(3) = length(VALUE);
606 if any(VALUE~=VALUE(1))
607 fprintf(HDR.FILE.stderr,'Warning IOPEN: different BitsPerSample not supported.\n');
610 HDR.TIFF.Compression = VALUE;
612 HDR.FLAG.PhotometricInterpretation = ~VALUE;
614 HDR.FLAG.Thresholding = VALUE;
616 HDR.FLAG.CellWidth = VALUE;
618 HDR.FLAG.CellLength = VALUE;
620 HDR.FLAG.FillOrder = VALUE;
622 HDR.TIFF.DocumentName = VALUE;
624 HDR.TIFF.ImageDescription = VALUE;
626 HDR.TIFF.Maker = VALUE;
628 HDR.TIFF.Model = VALUE;
630 HDR.TIFF.StripOffset = VALUE;
632 HDR.TIFF.Orientation = VALUE;
634 HDR.TIFF.SamplesPerPixel = VALUE;
636 HDR.TIFF.RowsPerStrip = VALUE;
638 HDR.TIFF.StripByteCounts = VALUE;
644 HDR.TIFF.XResolution = VALUE;
646 HDR.TIFF.YResolution = VALUE;
648 HDR.TIFF.PlanarConfiguration = VALUE;
650 HDR.TIFF.PageName =
char(VALUE);
652 HDR.TIFF.Xposition = VALUE;
654 HDR.TIFF.Yposition = VALUE;
656 HDR.TIFF.FreeOffset = VALUE;
658 HDR.TIFF.FreeBytesCount = VALUE;
660 HDR.TIFF.GrayResponseUnit = VALUE;
662 HDR.TIFF.GrayResponseCurve = VALUE;
664 HDR.TIFF.T4Options = VALUE;
666 HDR.TIFF.T6Options = VALUE;
669 HDR.TIFF.ResolutionUnit = '';
671 HDR.TIFF.ResolutionUnit = 'Inch';
673 HDR.TIFF.ResolutionUnit = 'cm';
676 HDR.TIFF.PageNumber = VALUE;
678 HDR.TIFF.TansferFunction = VALUE;
680 HDR.Software = VALUE;
682 HDR.TIFF.DateTime = VALUE;
690 HDR.TIFF.HostComputer = VALUE;
692 HDR.TIFF.Predictor = VALUE;
694 HDR.TIFF.WhitePoint = VALUE;
696 HDR.TIFF.PrimaryChromatics = VALUE;
698 HDR.TIFF.ColorMap = reshape(VALUE,3,2^HDR.Bits(1))';
700 HDR.TIFF.HalftoneHints = VALUE;
702 HDR.TIFF.TileWidth = VALUE;
704 HDR.TIFF.TileLength = VALUE;
706 HDR.TIFF.TileOffset = VALUE;
708 HDR.TIFF.TileByteCount = VALUE;
710 HDR.TIFF.BadFaxLines = VALUE;
712 HDR.TIFF.CleanFaxData = VALUE;
714 HDR.TIFF.ConsecutiveBadFaxLines = VALUE;
716 HDR.TIFF.SubIFDs = VALUE;
718 HDR.TIFF.InkSet = VALUE;
720 HDR.TIFF.InkNames = VALUE;
722 HDR.TIFF.NumberOfInks = VALUE;
724 HDR.TIFF.DotRange = VALUE;
726 HDR.TIFF.TargetPrinter = VALUE;
728 HDR.TIFF.ExtraSamples = VALUE;
730 HDR.TIFF.SampleFormat = VALUE;
732 HDR.TIFF.SMinSampleValue = VALUE;
734 HDR.TIFF.SMaxSampleValue = VALUE;
736 HDR.TIFF.TransferRange = VALUE;
739 HDR.TIFF.JPEGProc = VALUE;
741 HDR.TIFF.JPEGInterchangeFormat = VALUE;
743 HDR.TIFF.JPEGInterchangeFormatLength = VALUE;
745 HDR.TIFF.JPEGRestartInterval = VALUE;
748 HDR.TIFF.JPEGLosslessPredictors = VALUE;
750 HDR.TIFF.JPEGPointTransforms = VALUE;
752 HDR.TIFF.JPEGQTables = VALUE;
754 HDR.TIFF.JPEGDCTables = VALUE;
756 HDR.TIFF.JPEGACTables = VALUE;
758 HDR.TIFF.YCbCrCoefficients = VALUE;
760 HDR.TIFF.YCbCrSubSampling = VALUE;
762 HDR.TIFF.YCbCrPositioning = VALUE;
764 HDR.TIFF.ReferenceBlackWhite = VALUE;
767 HDR.TIFF.XML_Packet =
char(VALUE);
770 HDR.TIFF.GEO.GTModelTypeGeoKey = VALUE;
772 HDR.TIFF.GEO.GTRasterTypeGeoKey = VALUE;
774 HDR.TIFF.GEO.GTCitationGeoKey = VALUE;
776 HDR.TIFF.GEO.GeographicTypeGeoKey = VALUE;
778 HDR.TIFF.GEO.GeogCitationGeoKey = VALUE;
780 HDR.TIFF.GEO.GeogGeodeticDatumGeoKey = VALUE;
782 HDR.TIFF.GEO.GeogPrimeMeridianGeoKey = VALUE;
784 HDR.TIFF.GEO.GeogLinearUnitsGeoKey = VALUE;
786 HDR.TIFF.GEO.GeogLinearUnitSizeGeoKey = VALUE;
788 HDR.TIFF.GEO.GeogAngularUnitsGeoKey = VALUE;
790 HDR.TIFF.GEO.GeogAngularUnitSizeGeoKey = VALUE;
792 HDR.TIFF.GEO.GeogPrimeMeridianLongGeoKey = VALUE;
794 HDR.TIFF.GEO.GeogPrimeMeridianLongGeoKey = VALUE;
797 HDR.TIFF.GEO.ProjectionGeoKey = VALUE;
800 HDR.TIFF.ImageId =
char(VALUE);
803 HDR.TIFF.Matteing = VALUE;
805 HDR.TIFF.DataType = VALUE;
807 HDR.TIFF.ImageDepth = VALUE;
809 HDR.TIFF.TileDepth = VALUE;
812 HDR.Copyright = VALUE;
815 HDR.EXIF.ExposureTime = VALUE;
817 HDR.EXIF.FNumber = VALUE;
820 HDR.TIFF.GEO.ModelPixelScale = VALUE;
822 HDR.TIFF.GEO.ModelTiepoint = VALUE';
825 HDR.TIFF.IT8.Site = VALUE;
827 HDR.TIFF.IT8.ColorSequence = VALUE;
829 HDR.TIFF.IT8.Header = VALUE;
831 HDR.TIFF.IT8.RasterPadding = VALUE;
833 HDR.TIFF.IT8.BitsPerRunLength = VALUE;
835 HDR.TIFF.IT8.BitsPerExtendedRunLength = VALUE;
837 HDR.TIFF.IT8.ColorTable = VALUE;
839 HDR.TIFF.IT8.ImageColorIndicator = VALUE;
841 HDR.TIFF.IT8.BKGColorIndicator = VALUE;
843 HDR.TIFF.IT8.ImageColorValue = VALUE;
845 HDR.TIFF.IT8.BKGColorValue = VALUE;
847 HDR.TIFF.IT8.PixelIntensityRange = VALUE;
849 HDR.TIFF.IT8.TransparencyIndicator = VALUE;
851 HDR.TIFF.IT8.ColorCharacterization = VALUE;
853 HDR.TIFF.IT8.t34030 = VALUE;
856 HDR.TIFF.Photoshop = VALUE;
858 HDR.TIFF.EXIF_IFD = VALUE;
861 HDR.TIFF.GEO.KeyDirectory = VALUE;
863 HDR.TIFF.GEO.ASCII_Params = VALUE;
866 HDR.EXIF.ExposureProgram = VALUE;
868 HDR.EXIF.SpectralSensitivity = VALUE;
870 HDR.EXIF.ISOSpeedRating = VALUE;
872 HDR.EXIF.ExifVersion = VALUE;
874 HDR.EXIF.DateTimeOriginal = VALUE;
876 HDR.EXIF.DateTimeDigitized = VALUE;
879 HDR.EXIF.ComponentsConfiguration = VALUE;
881 HDR.EXIF.CompressedBitsPerPixel = VALUE;
883 HDR.EXIF.ShutterSpeed = VALUE;
885 HDR.EXIF.Aperture = VALUE;
887 HDR.EXIF.Brightness = VALUE;
889 HDR.EXIF.ExposureBias = VALUE;
891 HDR.EXIF.MaxAperture = VALUE;
893 HDR.EXIF.SubjectDistance = VALUE;
895 HDR.EXIF.MeteringMode = VALUE;
897 HDR.EXIF.LightSource = VALUE;
899 HDR.EXIF.Flash = VALUE;
901 HDR.EXIF.FocalLength = VALUE;
903 HDR.EXIF.SubjectArea = VALUE;
906 HDR.EXIF.MakerNote = VALUE;
908 HDR.EXIF.UserComment = VALUE;
910 HDR.EXIF.SubSecTime = VALUE;
912 HDR.EXIF.SubSecTimeOriginal = VALUE;
914 HDR.EXIF.SubSecTimeDigitized = VALUE;
917 HDR.EXIF.FlashpixVersion = VALUE;
919 HDR.EXIF.ColorSpace = VALUE;
921 HDR.EXIF.PixelXDimension = VALUE;
923 HDR.EXIF.PixelYDimension = VALUE;
925 HDR.EXIF.RelatedSoundFile = VALUE;
928 HDR.EXIF.FlashEnergy = VALUE;
930 HDR.EXIF.SpatialFrequencyResponse = VALUE;
932 HDR.EXIF.FocalPlaneXResolution = VALUE;
934 HDR.EXIF.FocalPlaneYResolution = VALUE;
936 HDR.EXIF.FocalPlaneResolutionUnit = VALUE;
938 HDR.EXIF.SubjectLocation = VALUE;
940 HDR.EXIF.ExposureIndex = VALUE;
942 HDR.EXIF.SensingMethod = VALUE;
945 HDR.EXIF.FileSource = VALUE;
947 HDR.EXIF.SceneType = VALUE;
949 HDR.EXIF.CFAPattern = VALUE;
952 HDR.EXIF.CustomRendered = VALUE;
954 HDR.EXIF.ExposureMode = VALUE;
956 HDR.EXIF.WhiteBalance = VALUE;
958 HDR.EXIF.DigitalZoomRatio = VALUE;
960 HDR.EXIF.FocalLengthIn35mmFilm = VALUE;
962 HDR.EXIF.SceneCaptureType = VALUE;
964 HDR.EXIF.GainControl = VALUE;
966 HDR.EXIF.Contrast = VALUE;
968 HDR.EXIF.Saturation = VALUE;
970 HDR.EXIF.Sharpness = VALUE;
972 HDR.EXIF.DeviceSettingDescription = VALUE;
974 HDR.EXIF.SubjectDistanceRange = VALUE;
976 HDR.EXIF.ImageUniqueID = VALUE;
980 fprintf(HDR.FILE.stdout,'IOPEN(TIFF): TAG %d %xH used\n',TAG,TAG)
984 status = fseek(HDR.FILE.FID,POS+12+8*HDR.FLAG.BigTIFF,'bof');
986 [OFFSET, c] = fread(HDR.FILE.FID, 1, 'uint32');
988 HDR.GDFTYP = ['uint',int2str(HDR.Bits(1))];
992 elseif strcmp(HDR.TYPE,'IMAGE:XBM'),
993 HDR.FILE.FID = fopen(HDR.FileName,[HDR.FILE.PERMISSION,'t'],'ieee-le');
996 tmp = fgetl(HDR.FILE.FID);