1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| var
Source : PTiff;
BitsPerSampleValue: Word;
Width, Height : Cardinal;
SourceLine, DestLine : array of byte;
I, J : integer;
begin
// first step
Source:=TIFFOpen(FileName,'r');
assert(Source<>nil,'Source File Missing');
try
// checking file format
assert(TIFFGetField(Source,TIFFTAG_BITSPERSAMPLE,@BitsPerSampleValue)=1,
'Corrupted Source File with TIFFTAG_BITSPERSAMPLE');
assert(BitsPerSampleValue=8,'Source File is not a 8bit color depth');
assert(TIFFGetField(Source,TIFFTAG_SAMPLESPERPIXEL,@BitsPerSampleValue)=1,
'Corrupted Source File with TIFFTAG_SAMPLESPERPIXEL');
assert(BitsPerSampleValue=3,'Source File as not 3 samples per value');
// reading sizes
assert(TIFFGetField(Source,TIFFTAG_IMAGEWIDTH,@Width)=1,'Corrupted Source file with TIFFTAG_IMAGEWIDTH');
assert(TIFFGetField(Source,TIFFTAG_IMAGELENGTH,@Height)=1,'Corrupted Source file with TIFFTAG_IMAGELENGTH');
setLength(SourceLine,3*Width);
// calculating the density
FillChar(Density[0,0,0],16777216,0);
for J:=0 to Height-1 do
begin
TIFFReadScanline(Source,@(SourceLine[0]),J,0);
for I:=0 to Width-1 do
inc(Density[SourceLine[3*I],SourceLine[3*I+1],SourceLine[3*I+2]]);
end;
[...]
finally
TIFFClose(Source);
end; |
Partager