mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-01 01:39:36 +01:00
fcl-image: tiff: read/write PageName, fixed typos
git-svn-id: trunk@21517 -
This commit is contained in:
parent
fd18003cd6
commit
9636202165
@ -101,9 +101,10 @@ type
|
|||||||
Predictor: word; var LastValue: word; out Value: Word); inline;
|
Predictor: word; var LastValue: word; out Value: Word); inline;
|
||||||
function FixEndian(w: Word): Word; inline;
|
function FixEndian(w: Word): Word; inline;
|
||||||
function FixEndian(d: DWord): DWord; inline;
|
function FixEndian(d: DWord): DWord; inline;
|
||||||
|
procedure SetFPImgExtras(CurImg: TFPCustomImage);
|
||||||
procedure DecodePackBits(var Buffer: Pointer; var Count: PtrInt);
|
procedure DecodePackBits(var Buffer: Pointer; var Count: PtrInt);
|
||||||
procedure DecodeLZW(var Buffer: Pointer; var Count: PtrInt);
|
procedure DecodeLZW(var Buffer: Pointer; var Count: PtrInt);
|
||||||
procedure SetFPImgExtras(CurImg: TFPCustomImage);
|
procedure DecodeDeflatePKZip(var Buffer: Pointer; var Count: PtrInt);
|
||||||
protected
|
protected
|
||||||
procedure InternalRead(Str: TStream; AnImage: TFPCustomImage); override;
|
procedure InternalRead(Str: TStream; AnImage: TFPCustomImage); override;
|
||||||
function InternalCheck(Str: TStream): boolean; override;
|
function InternalCheck(Str: TStream): boolean; override;
|
||||||
@ -137,6 +138,8 @@ procedure DecompressPackBits(Buffer: Pointer; Count: PtrInt;
|
|||||||
out NewBuffer: Pointer; out NewCount: PtrInt);
|
out NewBuffer: Pointer; out NewCount: PtrInt);
|
||||||
procedure DecompressLZW(Buffer: Pointer; Count: PtrInt;
|
procedure DecompressLZW(Buffer: Pointer; Count: PtrInt;
|
||||||
out NewBuffer: PByte; out NewCount: PtrInt);
|
out NewBuffer: PByte; out NewCount: PtrInt);
|
||||||
|
procedure DecompressDeflatePKZip(Buffer: Pointer; Count: PtrInt;
|
||||||
|
out NewBuffer: PByte; out NewCount: PtrInt);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -337,6 +340,7 @@ begin
|
|||||||
CurImg.Extra[TiffPageNumber]:=IntToStr(IFD.PageNumber);
|
CurImg.Extra[TiffPageNumber]:=IntToStr(IFD.PageNumber);
|
||||||
CurImg.Extra[TiffPageCount]:=IntToStr(IFD.PageCount);
|
CurImg.Extra[TiffPageCount]:=IntToStr(IFD.PageCount);
|
||||||
end;
|
end;
|
||||||
|
CurImg.Extra[TiffPageName]:=IFD.PageName;
|
||||||
if IFD.ImageIsThumbNail then
|
if IFD.ImageIsThumbNail then
|
||||||
CurImg.Extra[TiffIsThumbnail]:='1';
|
CurImg.Extra[TiffIsThumbnail]:='1';
|
||||||
if IFD.ImageIsMask then
|
if IFD.ImageIsMask then
|
||||||
@ -665,7 +669,7 @@ begin
|
|||||||
TiffCompressionDeflateAdobe,
|
TiffCompressionDeflateAdobe,
|
||||||
TiffCompressionJBIGBW,
|
TiffCompressionJBIGBW,
|
||||||
TiffCompressionJBIGCol,
|
TiffCompressionJBIGCol,
|
||||||
TiffCompressionNext,
|
TiffCompressionNeXT,
|
||||||
TiffCompressionCCITTRLEW,
|
TiffCompressionCCITTRLEW,
|
||||||
TiffCompressionPackBits,
|
TiffCompressionPackBits,
|
||||||
TiffCompressionThunderScan,
|
TiffCompressionThunderScan,
|
||||||
@ -675,7 +679,7 @@ begin
|
|||||||
TiffCompressionIT8BL,
|
TiffCompressionIT8BL,
|
||||||
TiffCompressionPixarFilm,
|
TiffCompressionPixarFilm,
|
||||||
TiffCompressionPixarLog,
|
TiffCompressionPixarLog,
|
||||||
TiffCompressionDeflate,
|
TiffCompressionDeflatePKZip,
|
||||||
TiffCompressionDCS,
|
TiffCompressionDCS,
|
||||||
TiffCompressionJBIG,
|
TiffCompressionJBIG,
|
||||||
TiffCompressionSGILog,
|
TiffCompressionSGILog,
|
||||||
@ -722,19 +726,19 @@ begin
|
|||||||
end;
|
end;
|
||||||
263:
|
263:
|
||||||
begin
|
begin
|
||||||
// Treshholding
|
// Tresholding
|
||||||
UValue:=ReadEntryUnsigned;
|
UValue:=ReadEntryUnsigned;
|
||||||
case UValue of
|
case UValue of
|
||||||
1: ; // no dithering or halftoning was applied
|
1: ; // no dithering or halftoning was applied
|
||||||
2: ; // an ordered dithering or halftoning was applied
|
2: ; // an ordered dithering or halftoning was applied
|
||||||
3: ; // a randomized dithering or halftoning was applied
|
3: ; // a randomized dithering or halftoning was applied
|
||||||
else
|
else
|
||||||
TiffError('expected Treshholding, but found '+IntToStr(UValue));
|
TiffError('expected Tresholding, but found '+IntToStr(UValue));
|
||||||
end;
|
end;
|
||||||
IFD.Treshholding:=UValue;
|
IFD.Tresholding:=UValue;
|
||||||
{$ifdef FPC_Debug_Image}
|
{$ifdef FPC_Debug_Image}
|
||||||
if Debug then
|
if Debug then
|
||||||
writeln('TFPReaderTiff.ReadDirectoryEntry Tag 263: Treshholding=',IFD.Treshholding);
|
writeln('TFPReaderTiff.ReadDirectoryEntry Tag 263: Tresholding=',IFD.Tresholding);
|
||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
264:
|
264:
|
||||||
@ -941,6 +945,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
285:
|
||||||
|
begin
|
||||||
|
// PageName
|
||||||
|
IFD.PageName:=ReadEntryString;
|
||||||
|
{$ifdef FPC_Debug_Image}
|
||||||
|
if Debug then
|
||||||
|
writeln('TFPReaderTiff.ReadDirectoryEntry Tag 285: PageName="'+IFD.PageName+'"');
|
||||||
|
{$endif}
|
||||||
|
end;
|
||||||
288:
|
288:
|
||||||
begin
|
begin
|
||||||
// FreeOffsets
|
// FreeOffsets
|
||||||
@ -1681,8 +1694,9 @@ begin
|
|||||||
TiffCompressionNone: ; // not compressed
|
TiffCompressionNone: ; // not compressed
|
||||||
TiffCompressionPackBits: DecodePackBits(Chunk,CurByteCnt); // packbits
|
TiffCompressionPackBits: DecodePackBits(Chunk,CurByteCnt); // packbits
|
||||||
TiffCompressionLZW: DecodeLZW(Chunk,CurByteCnt); // LZW
|
TiffCompressionLZW: DecodeLZW(Chunk,CurByteCnt); // LZW
|
||||||
|
TiffCompressionDeflatePKZip: DecodeDeflatePKZip(Chunk,CurByteCnt); // Deflate
|
||||||
else
|
else
|
||||||
TiffError('compression '+IntToStr(IFD.Compression)+' not supported yet');
|
TiffError('compression '+TiffCompressionName(IFD.Compression)+' not supported yet');
|
||||||
end;
|
end;
|
||||||
if CurByteCnt<=0 then continue;
|
if CurByteCnt<=0 then continue;
|
||||||
if ChunkType=tctTile then begin
|
if ChunkType=tctTile then begin
|
||||||
@ -1861,6 +1875,17 @@ begin
|
|||||||
Count:=NewCount;
|
Count:=NewCount;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TFPReaderTiff.DecodeDeflatePKZip(var Buffer: Pointer; var Count: PtrInt);
|
||||||
|
var
|
||||||
|
NewBuffer: Pointer;
|
||||||
|
NewCount: PtrInt;
|
||||||
|
begin
|
||||||
|
DecompressDeflatePKZip(Buffer,Count,NewBuffer,NewCount);
|
||||||
|
FreeMem(Buffer);
|
||||||
|
Buffer:=NewBuffer;
|
||||||
|
Count:=NewCount;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TFPReaderTiff.InternalRead(Str: TStream; AnImage: TFPCustomImage);
|
procedure TFPReaderTiff.InternalRead(Str: TStream; AnImage: TFPCustomImage);
|
||||||
// read the biggest image
|
// read the biggest image
|
||||||
var
|
var
|
||||||
@ -2233,6 +2258,15 @@ begin
|
|||||||
ReAllocMem(NewBuffer,NewCount);
|
ReAllocMem(NewBuffer,NewCount);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure DecompressDeflatePKZip(Buffer: Pointer; Count: PtrInt; out
|
||||||
|
NewBuffer: PByte; out NewCount: PtrInt);
|
||||||
|
begin
|
||||||
|
NewBuffer:=nil;
|
||||||
|
NewCount:=0;
|
||||||
|
if Count=0 then exit;
|
||||||
|
raise Exception.Create('decompressing Deflate PKZip not yet supported');
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
if ImageHandlers.ImageReader[TiffHandlerName]=nil then
|
if ImageHandlers.ImageReader[TiffHandlerName]=nil then
|
||||||
ImageHandlers.RegisterImageReader (TiffHandlerName, 'tif;tiff', TFPReaderTiff);
|
ImageHandlers.RegisterImageReader (TiffHandlerName, 'tif;tiff', TFPReaderTiff);
|
||||||
|
|||||||
@ -56,6 +56,7 @@ const
|
|||||||
TiffYResolution = TiffExtraPrefix+'YResolution';
|
TiffYResolution = TiffExtraPrefix+'YResolution';
|
||||||
TiffPageNumber = TiffExtraPrefix+'PageNumber'; // starting at 0
|
TiffPageNumber = TiffExtraPrefix+'PageNumber'; // starting at 0
|
||||||
TiffPageCount = TiffExtraPrefix+'PageCount'; // if >0 the image is a page
|
TiffPageCount = TiffExtraPrefix+'PageCount'; // if >0 the image is a page
|
||||||
|
TiffPageName = TiffExtraPrefix+'PageName';
|
||||||
TiffIsThumbnail = TiffExtraPrefix+'IsThumbnail';
|
TiffIsThumbnail = TiffExtraPrefix+'IsThumbnail';
|
||||||
TiffIsMask = TiffExtraPrefix+'IsMask';
|
TiffIsMask = TiffExtraPrefix+'IsMask';
|
||||||
TiffTileWidth = TiffExtraPrefix+'TileWidth';
|
TiffTileWidth = TiffExtraPrefix+'TileWidth';
|
||||||
@ -74,7 +75,7 @@ const
|
|||||||
TiffCompressionDeflateAdobe = 8; { Deflate Adobe style }
|
TiffCompressionDeflateAdobe = 8; { Deflate Adobe style }
|
||||||
TiffCompressionJBIGBW = 9; { RFC2301 JBIG black/white }
|
TiffCompressionJBIGBW = 9; { RFC2301 JBIG black/white }
|
||||||
TiffCompressionJBIGCol = 10; { RFC2301 JBIG color }
|
TiffCompressionJBIGCol = 10; { RFC2301 JBIG color }
|
||||||
TiffCompressionNext = 32766; { Next }
|
TiffCompressionNeXT = 32766; { Next }
|
||||||
TiffCompressionCCITTRLEW = 32771; { CCITTRLEW }
|
TiffCompressionCCITTRLEW = 32771; { CCITTRLEW }
|
||||||
TiffCompressionPackBits = 32773; { PackBits Compression, a simple byte-oriented run length scheme.
|
TiffCompressionPackBits = 32773; { PackBits Compression, a simple byte-oriented run length scheme.
|
||||||
See the PackBits section for details. Data Compression applies
|
See the PackBits section for details. Data Compression applies
|
||||||
@ -86,7 +87,7 @@ const
|
|||||||
TiffCompressionIT8BL = 32898; { IT8BL }
|
TiffCompressionIT8BL = 32898; { IT8BL }
|
||||||
TiffCompressionPixarFilm = 32908; { PIXARFILM }
|
TiffCompressionPixarFilm = 32908; { PIXARFILM }
|
||||||
TiffCompressionPixarLog = 32909; { PIXARLOG }
|
TiffCompressionPixarLog = 32909; { PIXARLOG }
|
||||||
TiffCompressionDeflate = 32946; { DEFLATE }
|
TiffCompressionDeflatePKZip = 32946; { DeflatePKZip }
|
||||||
TiffCompressionDCS = 32947; { DCS }
|
TiffCompressionDCS = 32947; { DCS }
|
||||||
TiffCompressionJBIG = 34661; { JBIG }
|
TiffCompressionJBIG = 34661; { JBIG }
|
||||||
TiffCompressionSGILog = 34676; { SGILOG }
|
TiffCompressionSGILog = 34676; { SGILOG }
|
||||||
@ -129,6 +130,7 @@ type
|
|||||||
Orientation: DWord;
|
Orientation: DWord;
|
||||||
PageNumber: word; // the page number starting at 0, the total number of pages is PageCount
|
PageNumber: word; // the page number starting at 0, the total number of pages is PageCount
|
||||||
PageCount: word; // see PageNumber
|
PageCount: word; // see PageNumber
|
||||||
|
PageName: string;
|
||||||
PhotoMetricInterpretation: DWord;
|
PhotoMetricInterpretation: DWord;
|
||||||
PlanarConfiguration: DWord;
|
PlanarConfiguration: DWord;
|
||||||
ResolutionUnit: DWord;
|
ResolutionUnit: DWord;
|
||||||
@ -141,7 +143,7 @@ type
|
|||||||
TileLength: DWord; // = Height
|
TileLength: DWord; // = Height
|
||||||
TileOffsets: DWord; // tiff position of entry
|
TileOffsets: DWord; // tiff position of entry
|
||||||
TileByteCounts: DWord; // tiff position of entry
|
TileByteCounts: DWord; // tiff position of entry
|
||||||
Treshholding: DWord;
|
Tresholding: DWord;
|
||||||
XResolution: TTiffRational;
|
XResolution: TTiffRational;
|
||||||
YResolution: TTiffRational;
|
YResolution: TTiffRational;
|
||||||
// image
|
// image
|
||||||
@ -228,7 +230,7 @@ begin
|
|||||||
8: Result:='Deflate Adobe style';
|
8: Result:='Deflate Adobe style';
|
||||||
9: Result:='RFC2301 JBIG white/black';
|
9: Result:='RFC2301 JBIG white/black';
|
||||||
10: Result:='RFC2301 JBIG color';
|
10: Result:='RFC2301 JBIG color';
|
||||||
32766: Result:='Next';
|
32766: Result:='NeXT';
|
||||||
32771: Result:='CCITTRLEW';
|
32771: Result:='CCITTRLEW';
|
||||||
32773: Result:='PackBits';
|
32773: Result:='PackBits';
|
||||||
32809: Result:='THUNDERSCAN';
|
32809: Result:='THUNDERSCAN';
|
||||||
@ -238,13 +240,13 @@ begin
|
|||||||
32898: Result:='IT8BL';
|
32898: Result:='IT8BL';
|
||||||
32908: Result:='PIXARFILM';
|
32908: Result:='PIXARFILM';
|
||||||
32909: Result:='PIXARLOG';
|
32909: Result:='PIXARLOG';
|
||||||
32946: Result:='DEFLATE';
|
32946: Result:='Deflate PKZip';
|
||||||
32947: Result:='DCS';
|
32947: Result:='DCS';
|
||||||
34661: Result:='JBIG';
|
34661: Result:='JBIG';
|
||||||
34676: Result:='SGILOG';
|
34676: Result:='SGILOG';
|
||||||
34677: Result:='SGILOG24';
|
34677: Result:='SGILOG24';
|
||||||
34712: Result:='JP2000';
|
34712: Result:='JP2000';
|
||||||
else Result:='unknown';
|
else Result:='unknown('+IntToStr(c)+')';
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -286,6 +288,7 @@ begin
|
|||||||
Orientation:=0;
|
Orientation:=0;
|
||||||
PageNumber:=0;
|
PageNumber:=0;
|
||||||
PageCount:=0;
|
PageCount:=0;
|
||||||
|
PageName:='';
|
||||||
|
|
||||||
// tiles
|
// tiles
|
||||||
TileWidth:=0;
|
TileWidth:=0;
|
||||||
@ -293,7 +296,7 @@ begin
|
|||||||
TileOffsets:=0;
|
TileOffsets:=0;
|
||||||
TileByteCounts:=0;
|
TileByteCounts:=0;
|
||||||
|
|
||||||
Treshholding:=0;
|
Tresholding:=0;
|
||||||
|
|
||||||
RedBits:=0;
|
RedBits:=0;
|
||||||
GreenBits:=0;
|
GreenBits:=0;
|
||||||
@ -345,6 +348,7 @@ begin
|
|||||||
Orientation:=IFD.Orientation;
|
Orientation:=IFD.Orientation;
|
||||||
PageNumber:=IFD.PageNumber;
|
PageNumber:=IFD.PageNumber;
|
||||||
PageCount:=IFD.PageCount;
|
PageCount:=IFD.PageCount;
|
||||||
|
PageName:=IFD.PageName;
|
||||||
|
|
||||||
// tiles
|
// tiles
|
||||||
TileWidth:=IFD.TileWidth;
|
TileWidth:=IFD.TileWidth;
|
||||||
@ -352,7 +356,7 @@ begin
|
|||||||
TileOffsets:=IFD.TileOffsets;
|
TileOffsets:=IFD.TileOffsets;
|
||||||
TileByteCounts:=IFD.TileByteCounts;
|
TileByteCounts:=IFD.TileByteCounts;
|
||||||
|
|
||||||
Treshholding:=IFD.Treshholding;
|
Tresholding:=IFD.Tresholding;
|
||||||
|
|
||||||
RedBits:=IFD.RedBits;
|
RedBits:=IFD.RedBits;
|
||||||
GreenBits:=IFD.GreenBits;
|
GreenBits:=IFD.GreenBits;
|
||||||
@ -389,6 +393,7 @@ begin
|
|||||||
YResolution:=StrToTiffRationalDef(Src.Extra[TiffYResolution],TiffRational72);
|
YResolution:=StrToTiffRationalDef(Src.Extra[TiffYResolution],TiffRational72);
|
||||||
PageNumber:=StrToIntDef(Src.Extra[TiffPageNumber],0);
|
PageNumber:=StrToIntDef(Src.Extra[TiffPageNumber],0);
|
||||||
PageCount:=StrToIntDef(Src.Extra[TiffPageCount],0);
|
PageCount:=StrToIntDef(Src.Extra[TiffPageCount],0);
|
||||||
|
PageName:=Src.Extra[TiffPageName];
|
||||||
ImageIsPage:=PageCount>0;
|
ImageIsPage:=PageCount>0;
|
||||||
ImageIsThumbNail:=Src.Extra[TiffIsThumbnail]<>'';
|
ImageIsThumbNail:=Src.Extra[TiffIsThumbnail]<>'';
|
||||||
ImageIsMask:=Src.Extra[TiffIsMask]<>'';
|
ImageIsMask:=Src.Extra[TiffIsMask]<>'';
|
||||||
|
|||||||
@ -423,6 +423,8 @@ begin
|
|||||||
Shorts[1]:=IFD.PageCount;
|
Shorts[1]:=IFD.PageCount;
|
||||||
AddEntry(297,3,2,@Shorts[0],2*SizeOf(Word));
|
AddEntry(297,3,2,@Shorts[0],2*SizeOf(Word));
|
||||||
end;
|
end;
|
||||||
|
if IFD.PageName<>'' then
|
||||||
|
AddEntryString(285,IFD.PageName);
|
||||||
if IFD.Copyright<>'' then
|
if IFD.Copyright<>'' then
|
||||||
AddEntryString(33432,IFD.Copyright);
|
AddEntryString(33432,IFD.Copyright);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user