Browse Source

fcl-image: tiff: read/write PageName, fixed typos

git-svn-id: trunk@21517 -
Mattias Gaertner 13 years ago
parent
commit
9636202165

+ 42 - 8
packages/fcl-image/src/fpreadtiff.pas

@@ -101,9 +101,10 @@ type
       Predictor: word; var LastValue: word; out Value: Word); inline;
     function FixEndian(w: Word): Word; inline;
     function FixEndian(d: DWord): DWord; inline;
+    procedure SetFPImgExtras(CurImg: TFPCustomImage);
     procedure DecodePackBits(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
     procedure InternalRead(Str: TStream; AnImage: TFPCustomImage); override;
     function InternalCheck(Str: TStream): boolean; override;
@@ -137,6 +138,8 @@ procedure DecompressPackBits(Buffer: Pointer; Count: PtrInt;
   out NewBuffer: Pointer; out NewCount: PtrInt);
 procedure DecompressLZW(Buffer: Pointer; Count: PtrInt;
   out NewBuffer: PByte; out NewCount: PtrInt);
+procedure DecompressDeflatePKZip(Buffer: Pointer; Count: PtrInt;
+  out NewBuffer: PByte; out NewCount: PtrInt);
 
 implementation
 
@@ -337,6 +340,7 @@ begin
     CurImg.Extra[TiffPageNumber]:=IntToStr(IFD.PageNumber);
     CurImg.Extra[TiffPageCount]:=IntToStr(IFD.PageCount);
   end;
+  CurImg.Extra[TiffPageName]:=IFD.PageName;
   if IFD.ImageIsThumbNail then
     CurImg.Extra[TiffIsThumbnail]:='1';
   if IFD.ImageIsMask then
@@ -665,7 +669,7 @@ begin
       TiffCompressionDeflateAdobe,
       TiffCompressionJBIGBW,
       TiffCompressionJBIGCol,
-      TiffCompressionNext,
+      TiffCompressionNeXT,
       TiffCompressionCCITTRLEW,
       TiffCompressionPackBits,
       TiffCompressionThunderScan,
@@ -675,7 +679,7 @@ begin
       TiffCompressionIT8BL,
       TiffCompressionPixarFilm,
       TiffCompressionPixarLog,
-      TiffCompressionDeflate,
+      TiffCompressionDeflatePKZip,
       TiffCompressionDCS,
       TiffCompressionJBIG,
       TiffCompressionSGILog,
@@ -722,19 +726,19 @@ begin
     end;
   263:
     begin
-      // Treshholding
+      // Tresholding
       UValue:=ReadEntryUnsigned;
       case UValue of
       1: ; // no dithering or halftoning was applied
       2: ; // an ordered dithering or halftoning was applied
       3: ; // a randomized dithering or halftoning was applied
       else
-        TiffError('expected Treshholding, but found '+IntToStr(UValue));
+        TiffError('expected Tresholding, but found '+IntToStr(UValue));
       end;
-      IFD.Treshholding:=UValue;
+      IFD.Tresholding:=UValue;
       {$ifdef FPC_Debug_Image}
       if Debug then
-        writeln('TFPReaderTiff.ReadDirectoryEntry Tag 263: Treshholding=',IFD.Treshholding);
+        writeln('TFPReaderTiff.ReadDirectoryEntry Tag 263: Tresholding=',IFD.Tresholding);
       {$endif}
     end;
   264:
@@ -941,6 +945,15 @@ begin
       end;
       {$endif}
     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:
     begin
       // FreeOffsets
@@ -1681,8 +1694,9 @@ begin
       TiffCompressionNone: ; // not compressed
       TiffCompressionPackBits: DecodePackBits(Chunk,CurByteCnt); // packbits
       TiffCompressionLZW: DecodeLZW(Chunk,CurByteCnt); // LZW
+      TiffCompressionDeflatePKZip: DecodeDeflatePKZip(Chunk,CurByteCnt); // Deflate
       else
-        TiffError('compression '+IntToStr(IFD.Compression)+' not supported yet');
+        TiffError('compression '+TiffCompressionName(IFD.Compression)+' not supported yet');
       end;
       if CurByteCnt<=0 then continue;
       if ChunkType=tctTile then begin
@@ -1861,6 +1875,17 @@ begin
   Count:=NewCount;
 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);
 // read the biggest image
 var
@@ -2233,6 +2258,15 @@ begin
   ReAllocMem(NewBuffer,NewCount);
 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
   if ImageHandlers.ImageReader[TiffHandlerName]=nil then
     ImageHandlers.RegisterImageReader (TiffHandlerName, 'tif;tiff', TFPReaderTiff);

+ 13 - 8
packages/fcl-image/src/fptiffcmn.pas

@@ -56,6 +56,7 @@ const
   TiffYResolution = TiffExtraPrefix+'YResolution';
   TiffPageNumber = TiffExtraPrefix+'PageNumber'; // starting at 0
   TiffPageCount = TiffExtraPrefix+'PageCount'; // if >0 the image is a page
+  TiffPageName = TiffExtraPrefix+'PageName';
   TiffIsThumbnail = TiffExtraPrefix+'IsThumbnail';
   TiffIsMask = TiffExtraPrefix+'IsMask';
   TiffTileWidth = TiffExtraPrefix+'TileWidth';
@@ -74,7 +75,7 @@ const
   TiffCompressionDeflateAdobe = 8; { Deflate Adobe style }
   TiffCompressionJBIGBW = 9; { RFC2301 JBIG black/white }
   TiffCompressionJBIGCol = 10; { RFC2301 JBIG color }
-  TiffCompressionNext = 32766; { Next }
+  TiffCompressionNeXT = 32766; { Next }
   TiffCompressionCCITTRLEW = 32771; { CCITTRLEW }
   TiffCompressionPackBits = 32773; { PackBits Compression, a simple byte-oriented run length scheme.
          See the PackBits section for details. Data Compression applies
@@ -86,7 +87,7 @@ const
   TiffCompressionIT8BL = 32898; { IT8BL }
   TiffCompressionPixarFilm = 32908; { PIXARFILM }
   TiffCompressionPixarLog = 32909; { PIXARLOG }
-  TiffCompressionDeflate = 32946; { DEFLATE }
+  TiffCompressionDeflatePKZip = 32946; { DeflatePKZip }
   TiffCompressionDCS = 32947; { DCS }
   TiffCompressionJBIG = 34661; { JBIG }
   TiffCompressionSGILog = 34676; { SGILOG }
@@ -129,6 +130,7 @@ type
     Orientation: DWord;
     PageNumber: word; // the page number starting at 0, the total number of pages is PageCount
     PageCount: word; // see PageNumber
+    PageName: string;
     PhotoMetricInterpretation: DWord;
     PlanarConfiguration: DWord;
     ResolutionUnit: DWord;
@@ -141,7 +143,7 @@ type
     TileLength: DWord; // = Height
     TileOffsets: DWord; // tiff position of entry
     TileByteCounts: DWord; // tiff position of entry
-    Treshholding: DWord;
+    Tresholding: DWord;
     XResolution: TTiffRational;
     YResolution: TTiffRational;
     // image
@@ -228,7 +230,7 @@ begin
   8: Result:='Deflate Adobe style';
   9: Result:='RFC2301 JBIG white/black';
   10: Result:='RFC2301 JBIG color';
-  32766: Result:='Next';
+  32766: Result:='NeXT';
   32771: Result:='CCITTRLEW';
   32773: Result:='PackBits';
   32809: Result:='THUNDERSCAN';
@@ -238,13 +240,13 @@ begin
   32898: Result:='IT8BL';
   32908: Result:='PIXARFILM';
   32909: Result:='PIXARLOG';
-  32946: Result:='DEFLATE';
+  32946: Result:='Deflate PKZip';
   32947: Result:='DCS';
   34661: Result:='JBIG';
   34676: Result:='SGILOG';
   34677: Result:='SGILOG24';
   34712: Result:='JP2000';
-  else Result:='unknown';
+  else Result:='unknown('+IntToStr(c)+')';
   end;
 end;
 
@@ -286,6 +288,7 @@ begin
   Orientation:=0;
   PageNumber:=0;
   PageCount:=0;
+  PageName:='';
 
   // tiles
   TileWidth:=0;
@@ -293,7 +296,7 @@ begin
   TileOffsets:=0;
   TileByteCounts:=0;
 
-  Treshholding:=0;
+  Tresholding:=0;
 
   RedBits:=0;
   GreenBits:=0;
@@ -345,6 +348,7 @@ begin
   Orientation:=IFD.Orientation;
   PageNumber:=IFD.PageNumber;
   PageCount:=IFD.PageCount;
+  PageName:=IFD.PageName;
 
   // tiles
   TileWidth:=IFD.TileWidth;
@@ -352,7 +356,7 @@ begin
   TileOffsets:=IFD.TileOffsets;
   TileByteCounts:=IFD.TileByteCounts;
 
-  Treshholding:=IFD.Treshholding;
+  Tresholding:=IFD.Tresholding;
 
   RedBits:=IFD.RedBits;
   GreenBits:=IFD.GreenBits;
@@ -389,6 +393,7 @@ begin
   YResolution:=StrToTiffRationalDef(Src.Extra[TiffYResolution],TiffRational72);
   PageNumber:=StrToIntDef(Src.Extra[TiffPageNumber],0);
   PageCount:=StrToIntDef(Src.Extra[TiffPageCount],0);
+  PageName:=Src.Extra[TiffPageName];
   ImageIsPage:=PageCount>0;
   ImageIsThumbNail:=Src.Extra[TiffIsThumbnail]<>'';
   ImageIsMask:=Src.Extra[TiffIsMask]<>'';

+ 2 - 0
packages/fcl-image/src/fpwritetiff.pas

@@ -423,6 +423,8 @@ begin
       Shorts[1]:=IFD.PageCount;
       AddEntry(297,3,2,@Shorts[0],2*SizeOf(Word));
     end;
+    if IFD.PageName<>'' then
+      AddEntryString(285,IFD.PageName);
     if IFD.Copyright<>'' then
       AddEntryString(33432,IFD.Copyright);