home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / full / delphi / INFO / EXTRAS / FIF / FIFDLLS.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1997-03-13  |  30.9 KB  |  795 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Delphi Supplemental Components                  }
  4. {       Fractal Image File (FIF) DLL binding            }
  5. {       Copyright (c) 1997 Borland International        }
  6. {                                                       }
  7. {       Requires DECO_32.DLL by Iterated Systems        }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit fifdlls;
  12.  
  13. interface
  14.  
  15. uses Windows, SysUtils;
  16.  
  17. type
  18.   TISI_Callback = function (handle, PercentComplete: Longint): Longint; cdecl;
  19.  
  20.   (*
  21.    *   Pixel Order Constants, used in SetOutputFormat
  22.    *)
  23.  
  24. const
  25.   RED8           =    1;
  26.   GREEN8         =    2;
  27.   BLUE8          =    3;
  28.   NOT_USED       =    4;
  29.   BLANK8         =    5;
  30.   COLORMAP8      =   10;
  31.   RED5           =   20;
  32.   GREEN5         =   21;
  33.   BLUE5          =   22;
  34.   GRAY8          =  100;
  35.  
  36.   (*
  37.    *   Row Order Constants, used in SetOutputFormat
  38.    *)
  39.  
  40. const
  41.   TOP_LEFT       =  0;
  42.   BOTTOM_LEFT    =  1;
  43.  
  44.   (*
  45.    *    Physical Unit Constants, used in GetPhysicalDimensions
  46.    *)
  47.  
  48. const
  49.   METER_UNITS      =      $6D;                 (* 'm' *)
  50.   INCH_UNITS       =      $22;                 (* '"' *)
  51.   UNKNOWN_UNITS    =      $75;                 (* 'u' *)
  52.  
  53.   (*
  54.    *   Callback Constants, used in SetDecompressCallback
  55.    *)
  56.  
  57. const
  58.   CALLBACK_FREQ_NONE  = 0;
  59.   CALLBACK_FREQ_LOW   = 1;
  60.   CALLBACK_FREQ_HIGH  = 2;
  61.  
  62.   (*
  63.    *   Colormap entryinfo, used in SetOutputColorTable
  64.    *)
  65.  
  66. const
  67.   CM_NOT_USED        =  0;
  68.   CM_STATIC          =  1;
  69.   CM_DYNAMIC         =  2;
  70.  
  71.   (*
  72.    *   FIF version number information
  73.    *)
  74.  
  75. const
  76.   VERSION_PRIMARY     = 6;
  77.   VERSION_SECONDARY   = 0;
  78.  
  79.   (*
  80.    *   Progressive FIF buffer location (see SetProgressiveFIFBuffer)
  81.    *)
  82.  
  83. const
  84.   FIF_BEGIN          =  0;
  85.   FIF_HEADER         =  1;
  86.   FIF_DATA           =  2;
  87.   FIF_COMPLETE       =  3;
  88.  
  89.   (*
  90.    *   Progressive FIF steps (see SetProgressiveStep)
  91.    *)
  92.  
  93. const
  94.   DECO_STEP_LAST     = -1;
  95.   DECO_STEP_FIRST    = -2;
  96.   DECO_STEP_ALL      = -3;
  97.   DECO_STEP_BEST     = -4;
  98.  
  99.   (*
  100.    *   Progressive decompression frequency (see ProgressiveDecompress)
  101.    *)
  102.  
  103. const
  104.   FREQUENCY_HIGH      =  0;
  105.   FREQUENCY_MEDIUM    =  1;
  106.   FREQUENCY_LOW       =  2;
  107.   FREQUENCY_NONE      =  3;
  108.  
  109.  
  110. type
  111.   TFIFOriginalImageInfo = record
  112.     Width, Height, ColorDepth: Longint;
  113.   end;
  114.  
  115.   TFIFDecodeSession = class
  116.   private
  117.     FHandle: Longint;
  118.     function GetFIFFTTFileName: string;
  119.     function GetFIFNumColors: Longint;
  120.     function GetFIFNumSteps: Longint;
  121.     function GetHandle: Longint;
  122.     function GetOriginalImageInfo: TFIFOriginalImageInfo;
  123.     function GetOutputDither: Boolean;
  124.     function GetOutputFilter: Boolean;
  125.     procedure SetOutputDither(Value: Boolean);
  126.     procedure SetOutputFilter(Value: Boolean);
  127.   public
  128.     constructor Create;
  129.     destructor Destroy; override;
  130.     procedure ClearFIFBuffer;
  131.     procedure ClearFTTBuffer;
  132.     procedure CloseDecompressor;
  133.     procedure DecompressToBuffer( ImageBuffer: Pointer;
  134.       CropPixelX, CropPixelY, CropPixelWidth, CropPixelHeight: Longint;
  135.       BytesPerRow: Longint );
  136.     procedure EndProgressiveDecompression;
  137.     procedure GetColorTableFormat( var ColorPlane0, ColorPlane1,
  138.       ColorPlane2, ColorPlane3: Longint);
  139.     class function GetDecoVersion( var MajorVer, MinorVer: Longint): Boolean;
  140.     procedure GetFastResolution( var PixelWidth, PixelHeight: Longint );
  141.     function GetFIFColorTable( ColorTable: Pointer ): Boolean;
  142.     procedure GetOutputColorTable( ColorTable: Pointer );
  143.     procedure GetOutputFormat( var ColorPlane0, ColorPlane1, ColorPlane2,
  144.       ColorPlane3, RowOrder: Longint );
  145.     procedure GetOutputResolution( var PixelWidth, PixelHeight: Longint );
  146.     procedure GetPhysicalDimensions( var PhysicalWidth, PhysicalHeight: Longint;
  147.       var PhysicalUnits: Byte; var PhysicalUnitScaleFactor: Longint );
  148.     procedure ProgressiveDecompress( Frequency: Longint;
  149.       var OutputBufferX, OutputBufferY, OutputBufferWidth, OutputBufferHeight,
  150.           BytesNeeded, PercentDone: Longint );
  151.     procedure SetColorTableFormat( ColorPlane0, ColorPlane1, ColorPlane2,
  152.       ColorPlane3: Longint );
  153.     procedure SetDecompressCallback( CallbackFunc: TISI_Callback;
  154.       CallbackFreq: Longint );
  155.     procedure SetFIFBuffer( Buffer: Pointer; Size: Longint );
  156.     procedure SetFTTBuffer( Buffer: Pointer; Size: Longint );
  157.     procedure SetOutputColorTable( ColorTable: Pointer; EntryInfo: Pointer;
  158.       NumColors: Longint );
  159.     procedure SetOutputFormat( ColorPlane0, ColorPlane1, ColorPlane2,
  160.       ColorPlane3, RowOrder: Longint );
  161.     procedure SetOutputResolution( PixelWidth, PixelHeight: Longint );
  162.     procedure SetProgressiveFIFBuffer( Buffer: Pointer;
  163.       Size: Longint; var InputStatus, HeaderLength: Longint );
  164.     procedure SetProgressiveStep( StepNumber: Longint );
  165.     procedure StartProgressiveDecompression( ImageBuffer: Pointer;
  166.       CropPixelX, CropPixelY, CropPixelWidth, CropPixelHeight,
  167.       BytesPerRow, Expand: Longint );
  168.     class function TestIfFIF( Buffer: Pointer; Length: Longint): Boolean;
  169.     property Dither: Boolean read GetOutputDither write SetOutputDither;
  170.     property Filter: Boolean read GetOutputFilter write SetOutputFilter;
  171.     property FTTFileName: String read GetFIFFTTFilename;
  172.     property Handle: Longint read GetHandle;
  173.     property NumColors: Longint read GetFIFNumColors;
  174.     property OriginalImage: TFIFOriginalImageInfo read GetOriginalImageInfo;
  175.     property Steps: Longint read GetFIFNumSteps;
  176.   end;
  177.  
  178.   EFIFError = class(Exception);
  179.  
  180. const
  181.   FIFDecodeDLLName = 'deco_32.dll';
  182.  
  183. function LoadFIFDecodeLibrary(FilePath: string; RaiseExceptions: Boolean): Boolean;
  184. procedure UnloadFIFDecodeLibrary;
  185. procedure FIFCheck(Result: Longint);
  186.  
  187. { Error codes }
  188. const
  189.   ISI_OK          = 0 ;  // Operation successful.
  190.   ISI_CANCEL      = -2;  // User canceled operation.
  191.  
  192.  
  193. // Memory Error Codes:
  194.   ISI_GLOBAL_ALLOC_ERROR = -20;   // Could not allocate global memory.
  195.   ISI_GLOBAL_FREE_ERROR  = -21;   // Could not free global memory.
  196.   ISI_LOCAL_ALLOC_ERROR  = -30;   // Could not allocate local memory.
  197.   ISI_LOCAL_FREE_ERROR   = -31;   // Could not free local memory.
  198.   ISI_NULL_ERROR         = -40;   // Unexpected NULL pointer or handle.
  199.  
  200.  
  201. // Decompressor Error Codes:
  202.   DECO_NOT_INITIALIZED_ERROR        = -50;   // Decompressor not
  203.                                              // initialized.
  204.   DECO_BUSY_ERROR                   = -51;   // Decompressor busy,
  205.                                              // can't initialize.
  206.   DECO_ILLEGAL_HANDLE_ERROR         = -52;   // Decompressor instance
  207.                                              // handle invalid.
  208.   DECO_FIF_BUFFER_INCOMPLETE        = -53;   // FIF buffer length too
  209.                                              // small.
  210.   DECO_FTT_BUFFER_INCOMPLETE        = -54;   // FTT buffer length too
  211.                                              // small.
  212.   DECO_FIF_FORMAT_ERROR             = -55;   // Input in unknown file
  213.                                              // format.
  214.   DECO_CROP_RECT_ERROR              = -56;   // Error in cropping
  215.                                              // rectangle.
  216.   DECO_OUTPUT_FORMAT_ERROR          = -57;   // Output format invalid.
  217.   DECO_RESOLUTION_SIZE_ERROR        = -58;   // Output resolution
  218.                                              // invalid.
  219.   DECO_FTT_FORMAT_ERROR             = -59;   // FTT file in unknown or
  220.                                              // unsupported format.
  221.   DECO_FTT_NOT_PROVIDED_ERROR       = -60;   // FTT file needed but
  222.                                              // not provided.
  223.   DECO_FTT_INCORRECT_ERROR          = -61;   // Wrong FTT file for
  224.                                              // this FIF file.
  225.   DECO_FIF_UNSUPPORTED_ERROR        = -62;   // Input in unsupported
  226.                                              // file format.
  227.   DECO_NO_COLORMAP_ERROR            = -63;   // No color table
  228.                                              // provided for
  229.                                              // colormapping.
  230.   DECO_CALLBACK_ERROR               = -64;   // Callback function
  231.                                              // failed.
  232.   DECO_RESOLUTION_NOT_PROVIDED_ERROR= -65;   // No output resolution
  233.                                              // provided.
  234.   DECO_FIF_NOT_PROVIDED_ERROR       = -66;   // A call to SetFIFBuffer
  235.                                              // is required.
  236.   DECO_INVALID_STEP_ERROR           = -67;   // Invalid progressive
  237.                                              // step number.
  238.   DECO_NO_START_PROGRESSIVE_ERROR   = -68;   // Must call
  239.                                              // StartProgressiveDecomp
  240.                                              // ression first.
  241.   DECO_FIF_FUTURE_VERSION_ERROR     = -69;   // Input FIF file
  242.                                              // requires a newer
  243.                                              // version of the
  244.                                              // decompressor.
  245.  
  246. // Compressor Error Codes:
  247.   COMP_BUSY_ERROR                      = -100; // Compressor is
  248.                                                // already in use.
  249.   COMP_NOT_INITIALIZED_ERROR           = -101; // Compressor not
  250.                                                // initialized.
  251.   COMP_ILLEGAL_HANDLE_ERROR            = -102; // Compressor instance
  252.                                                // handle is invalid.
  253.   COMP_ILLEGAL_IMAGE_FORMAT_ERROR      = -120; // Image format given
  254.                                                // to SetInputFormat is
  255.                                                // not valid/supported.
  256.   COMP_IMAGE_SIZE_ERROR                = -121; // Image height or
  257.                                                // width is 0, or
  258.                                                // SetInputResolution
  259.                                                // was not called
  260.                                                // before attempting to
  261.                                                // compress an image.
  262.   COMP_IMAGE_ASPECT_RATIO_ERROR        = -122; // Physical aspect
  263.                                                // ratio is different
  264.                                                // from pixel aspect
  265.                                                // ratio.
  266.   COMP_MAX_COLORS_EXCEEDED_ERROR       = -123; // Color table has more
  267.                                                // than 256 colors.
  268.   COMP_RESET_ERROR                     = -132; // Compressor could not
  269.                                                // be reset to its
  270.                                                // default state.
  271.   COMP_TYPE_ERROR                      = -140; // The Compressor type
  272.                                                // passed to
  273.                                                // OpenCompressor is
  274.                                                // invalid.
  275.   COMP_NOT_INCREMENTAL_ERROR           = -150; // Incremental
  276.                                                // compression
  277.                                                // function was called
  278.                                                // without a previous
  279.                                                // call to
  280.                                                // StartIncrementalCom
  281.                                                // pression.
  282.   COMP_INCREMENTAL_COMPRESSION_COMPLETE= -151; // A call to
  283.                                                // GetNextImageRect
  284.                                                // was made when no
  285.                                                // more panels remain
  286.                                                // to be compressed.
  287.   COMP_UNKNOWN_INCREMENT_ERROR         = -152; // A call to
  288.                                                // GetNextImageRect is
  289.                                                // required.
  290.   COMP_SPEED_ERROR                     = -160; // Speed factor
  291.                                                // invalid.  Speed
  292.                                                // factor is an
  293.                                                // integer from 1 to
  294.                                                // 100.
  295.   COMP_QUALITY_ERROR                   = -161; // Quality factor
  296.                                                // invalid.  Quality
  297.                                                // factor is an
  298.                                                // integer from 1 to
  299.                                                // 100.
  300.   COMP_SEARCH_WIDTH_ERROR              = -170; // Search box width
  301.                                                // too small (<80).
  302.   COMP_SEARCH_HEIGHT_ERROR             = -171; // Search box height
  303.                                                // too small (<64).
  304.   COMP_NO_IMAGE_BUFFER_ERROR           = -190; // A call to
  305.                                                // SetImageBuffer is
  306.                                                // required.
  307.  
  308.  
  309. implementation
  310.  
  311. var
  312.   FIFDecodeLibraryHandle: THandle = 0;
  313.   SessionCount: Integer = 0;
  314.  
  315. var
  316.   _ClearFIFBuffer: function ( handle: Longint ): Longint cdecl;
  317.  
  318.   _ClearFTTBuffer: function ( handle: Longint ): Longint cdecl;
  319.  
  320.   _CloseDecompressor: function ( handle: Longint ): Longint cdecl;
  321.  
  322.   _DecompressToBuffer: function ( handle: Longint;
  323.                                  ImageBuffer: Pointer;
  324.                                  CropPixelX,
  325.                                  CropPixelY,
  326.                                  CropPixelWidth,
  327.                                  CropPixelHeight: Longint;
  328.                                  BytesPerRow: Longint ): Longint cdecl;
  329.  
  330.   _EndProgressiveDecompression: function ( handle: Longint ): Longint cdecl;
  331.  
  332.   _GetColorTableFormat: function ( handle: Longint;
  333.                                   var ColorPlane0,
  334.                                       ColorPlane1,
  335.                                       ColorPlane2,
  336.                                       ColorPlane3: Longint): Longint cdecl;
  337.  
  338.   _GetDecoVersion: function ( var MajorVer, MinorVe: Longint): Longint cdecl;
  339.  
  340.   _GetFastResolution: function ( handle: Longint;
  341.                                 var PixelWidth,
  342.                                     PixelHeight: Longint ): Longint cdecl;
  343.  
  344.   _GetFIFColorTable: function ( handle: Longint;
  345.                                ColorTable: Pointer ): Longint cdecl;
  346.  
  347.   _GetFIFFTTFileName: function ( handle: Longint;
  348.                                 FTTFileName: PChar ): Longint cdecl;
  349.  
  350.   _GetFIFNumColors: function ( handle: Longint;
  351.                               var NumColors: Longint ): Longint cdecl;
  352.  
  353.   _GetFIFNumSteps: function ( handle: Longint;
  354.                              var NumSteps: Longint ): Longint cdecl;
  355.  
  356.   _GetOriginalResolution: function ( handle: Longint;
  357.                                     var PixelWidth,
  358.                                         PixelHeight,
  359.                                         ImageDepth: Longint ): Longint cdecl;
  360.  
  361.   _GetOutputColorTable: function ( handle: Longint;
  362.                                   ColorTable: Pointer ): Longint cdecl;
  363.  
  364.   _GetOutputDither: function ( handle: Longint;
  365.                               var DitherFlag: Byte ): Longint cdecl;
  366.  
  367.   _GetOutputFilter: function ( handle: Longint;
  368.                               var FilterFlag: Byte ): Longint cdecl;
  369.  
  370.   _GetOutputFormat: function ( handle: Longint;
  371.                               var ColorPlane0,
  372.                                   ColorPlane1,
  373.                                   ColorPlane2,
  374.                                   ColorPlane3,
  375.                                   RowOrder: Longint ): Longint cdecl;
  376.  
  377.   _GetOutputResolution: function ( handle: Longint;
  378.                                   var PixelWidth,
  379.                                       PixelHeight: Longint ): Longint cdecl;
  380.  
  381.   _GetPhysicalDimensions: function ( handle: Longint;
  382.                                     var PhysicalWidth,
  383.                                         PhysicalHeight: Longint;
  384.                                     var PhysicalUnits: Byte;
  385.                                     var PhysicalUnitScaleFactor: Longint ): Longint cdecl;
  386.  
  387.   _OpenDecompressor: function ( var Handle: Longint ): Longint cdecl;
  388.  
  389.   _ProgressiveDecompress: function ( handle: Longint;
  390.                                     Frequency: Longint;
  391.                                     var OutputBufferX,
  392.                                         OutputBufferY,
  393.                                         OutputBufferWidth,
  394.                                         OutputBufferHeight,
  395.                                         BytesNeeded,
  396.                                         PercentDone: Longint ): Longint cdecl;
  397.  
  398.   _SetColorTableFormat: function ( handle: Longint;
  399.                                   ColorPlane0,
  400.                                   ColorPlane1,
  401.                                   ColorPlane2,
  402.                                   ColorPlane3: Longint ): Longint cdecl;
  403.  
  404.   _SetDecompressCallback: function ( handle: Longint;
  405.                                     CallbackFunc: TISI_Callback;
  406.                                     CallbackFreq: Longint ): Longint cdecl;
  407.  
  408.   _SetFIFBuffer: function ( handle: Longint;
  409.                            FIFBuffer: Pointer;
  410.                            FIFBufferSize: Longint ): Longint cdecl;
  411.  
  412.   _SetFTTBuffer: function ( handle: Longint;
  413.                            FTTBuffer: Pointer;
  414.                            FTTBufferSize: Longint ): Longint cdecl;
  415.  
  416.   _SetOutputColorTable: function ( handle: Longint;
  417.                                   ColorTable: Pointer;
  418.                                   EntryInfo: Pointer;
  419.                                   NumColors: Longint ): Longint cdecl;
  420.  
  421.   _SetOutputDither: function ( handle: Longint;
  422.                               DitherFlag: Boolean ): Longint cdecl;
  423.  
  424.   _SetOutputFilter: function ( handle: Longint;
  425.                               FilterFlag: Boolean ): Longint cdecl;
  426.  
  427.   _SetOutputFormat: function ( handle: Longint;
  428.                               ColorPlane0,
  429.                               ColorPlane1,
  430.                               ColorPlane2,
  431.                               ColorPlane3,
  432.                               RowOrder: Longint ): Longint cdecl;
  433.  
  434.   _SetOutputResolution: function ( handle: Longint;
  435.                                   PixelWidth,
  436.                                   PixelHeight: Longint ): Longint cdecl;
  437.  
  438.   _SetProgressiveFIFBuffer: function ( handle: Longint;
  439.                                       FIFBuffer: Pointer;
  440.                                       FIFBufferSize: Longint;
  441.                                       var InputStatus: Longint;
  442.                                       var HeaderLength: Longint ): Longint cdecl;
  443.  
  444.   _SetProgressiveStep: function ( handle: Longint;
  445.                                  StepNumber: Longint ): Longint cdecl;
  446.  
  447.   _StartProgressiveDecompression: function ( handle: Longint;
  448.                                             ImageBuffer: Pointer;
  449.                                             CropPixelX,
  450.                                             CropPixelY,
  451.                                             CropPixelWidth,
  452.                                             CropPixelHeight,
  453.                                             BytesPerRow,
  454.                                             Expand: Longint ): Longint cdecl;
  455.  
  456.   _TestIfFIF: function ( FileBuffer: Pointer;
  457.                         BufferLength: Longint;
  458.                         var IsFIF: Boolean ): Longint cdecl;
  459.  
  460.  
  461.  
  462. procedure FIFCheck(Result: Longint);
  463. begin
  464.   if Result <> 0 then
  465.     EFIFError.CreateFmt('Invalid FIF operation: %d', [Result]);
  466. end;
  467.  
  468. {  TFIFDecodeSession  }
  469.  
  470. constructor TFIFDecodeSession.Create;
  471. begin
  472.   inherited Create;
  473.   Inc(SessionCount);
  474.   LoadFIFDecodeLibrary('',True);
  475. end;
  476.  
  477. destructor TFIFDecodeSession.Destroy;
  478. begin
  479.   Dec(SessionCount);
  480.   CloseDecompressor;
  481.   inherited Destroy;
  482. end;
  483.  
  484. procedure TFIFDecodeSession.ClearFIFBuffer;
  485. begin
  486.   FIFCheck(_ClearFIFBuffer(Handle));
  487. end;
  488.  
  489. procedure TFIFDecodeSession.ClearFTTBuffer;
  490. begin
  491.   FIFCheck(_ClearFTTBuffer(Handle));
  492. end;
  493.  
  494. procedure TFIFDecodeSession.CloseDecompressor;
  495. begin
  496.   if FHandle <> 0 then
  497.   begin
  498.     _ClearFIFBuffer(FHandle);
  499.     _ClearFTTBuffer(FHandle);
  500.     FIFCheck(_CloseDecompressor(FHandle));
  501.   end;
  502.   FHandle := 0;
  503. end;
  504.  
  505. procedure TFIFDecodeSession.DecompressToBuffer( ImageBuffer: Pointer;
  506.   CropPixelX, CropPixelY, CropPixelWidth, CropPixelHeight: Longint;
  507.   BytesPerRow: Longint );
  508. begin
  509.   FIFCheck(_DecompressToBuffer(Handle, ImageBuffer, CropPixelX, CropPixelY,
  510.     CropPixelWidth, CropPixelHeight, BytesPerRow));
  511. end;
  512.  
  513. procedure TFIFDecodeSession.EndProgressiveDecompression;
  514. begin
  515.   FIFCheck(_EndProgressiveDecompression(FHandle));
  516. end;
  517.  
  518. procedure TFIFDecodeSession.GetColorTableFormat( var ColorPlane0, ColorPlane1,
  519.   ColorPlane2, ColorPlane3: Longint);
  520. begin
  521.   FIFCheck(_GetColorTableFormat(FHandle, ColorPlane0, ColorPlane1, ColorPlane2,
  522.     ColorPlane3));
  523. end;
  524.  
  525. class function TFIFDecodeSession.GetDecoVersion( var MajorVer, MinorVer: Longint): Boolean;
  526. begin
  527.   Result := LoadFIFDecodeLibrary('',False);
  528.   if Result then
  529.     _GetDecoVersion(MajorVer, MinorVer);
  530. end;
  531.  
  532. procedure TFIFDecodeSession.GetFastResolution( var PixelWidth, PixelHeight: Longint );
  533. begin
  534.   FIFCheck(_GetFastResolution(FHandle, PixelWidth, PixelHeight));
  535. end;
  536.  
  537. function TFIFDecodeSession.GetFIFColorTable( ColorTable: Pointer ): Boolean;
  538. var
  539.   ResultCode: Longint;
  540. begin
  541.   Result := False;
  542.   ResultCode := _GetFIFColorTable(FHandle, ColorTable);
  543.   if ResultCode <> DECO_NO_COLORMAP_ERROR then
  544.   begin
  545.     FIFCheck(ResultCode);
  546.     Result := True;
  547.   end;
  548. end;
  549.  
  550. function TFIFDecodeSession.GetFIFFTTFileName: string;
  551. var
  552.   Buf: array [Byte] of Char;
  553. begin
  554.   FIFCheck(_GetFIFFTTFileName(FHandle, Buf));
  555.   Result := Buf;
  556. end;
  557.  
  558. function TFIFDecodeSession.GetFIFNumColors: Longint;
  559. begin
  560.   FIFCheck(_GetFIFNumColors(FHandle, Result));
  561. end;
  562.  
  563. function TFIFDecodeSession.GetFIFNumSteps: Longint;
  564. begin
  565.   FIFCheck(_GetFIFNumSteps(FHandle, Result));
  566. end;
  567.  
  568. function TFIFDecodeSession.GetHandle: Longint;
  569. begin
  570.   if FHandle = 0 then
  571.     FIFCheck(_OpenDecompressor(FHandle));
  572.   Result := FHandle;
  573. end;
  574.  
  575. function TFIFDecodeSession.GetOriginalImageInfo: TFIFOriginalImageInfo;
  576. begin
  577.   FIFCheck(_GetOriginalResolution(FHandle, Result.Width, Result.Height,
  578.     Result.ColorDepth));
  579. end;
  580.  
  581. procedure TFIFDecodeSession.GetOutputColorTable( ColorTable: Pointer );
  582. begin
  583.   FIFCheck(_GetOutputColorTable(FHandle, ColorTable));
  584. end;
  585.  
  586. function TFIFDecodeSession.GetOutputDither: Boolean;
  587. var
  588.   Code: Byte;
  589. begin
  590.   FIFCheck(_GetOutputDither(FHandle, Code));
  591.   Result := Code <> 0;
  592. end;
  593.  
  594. function TFIFDecodeSession.GetOutputFilter: Boolean;
  595. var
  596.   Code: Byte;
  597. begin
  598.   FIFCheck(_GetOutputFilter(FHandle, Code));
  599.   Result := Code <> 0;
  600. end;
  601.  
  602. procedure TFIFDecodeSession.GetOutputFormat( var ColorPlane0, ColorPlane1, ColorPlane2,
  603.   ColorPlane3, RowOrder: Longint );
  604. begin
  605.   FIFCheck(_GetOutputFormat(FHandle, ColorPlane0, ColorPlane1, ColorPlane2,
  606.     ColorPlane3, RowOrder));
  607. end;
  608.  
  609. procedure TFIFDecodeSession.GetOutputResolution( var PixelWidth, PixelHeight: Longint );
  610. begin
  611.   FIFCheck(_GetOutputResolution(FHandle, PixelWidth, PixelHeight));
  612. end;
  613.  
  614. procedure TFIFDecodeSession.GetPhysicalDimensions( var PhysicalWidth, PhysicalHeight: Longint;
  615.   var PhysicalUnits: Byte; var PhysicalUnitScaleFactor: Longint );
  616. begin
  617.   FIFCheck(_GetPhysicalDimensions(FHandle, PhysicalWidth, PhysicalHeight,
  618.     PhysicalUnits, PhysicalUnitScaleFactor));
  619. end;
  620.  
  621. procedure TFIFDecodeSession.ProgressiveDecompress( Frequency: Longint;
  622.   var OutputBufferX, OutputBufferY, OutputBufferWidth, OutputBufferHeight,
  623.       BytesNeeded, PercentDone: Longint );
  624. begin
  625.   FIFCheck(_ProgressiveDecompress( FHandle, Frequency, OutputBufferX,
  626.     OutputBufferY, OutputBufferWidth, OutputBufferHeight, BytesNeeded,
  627.     PercentDone));
  628. end;
  629.  
  630. procedure TFIFDecodeSession.SetColorTableFormat( ColorPlane0, ColorPlane1, ColorPlane2,
  631.   ColorPlane3: Longint );
  632. begin
  633.   FIFCheck(_SetColorTableFormat(Handle, ColorPlane0, ColorPlane1, ColorPlane2,
  634.     ColorPlane3));
  635. end;
  636.  
  637. procedure TFIFDecodeSession.SetDecompressCallback( CallbackFunc: TISI_Callback;
  638.   CallbackFreq: Longint );
  639. begin
  640.   FIFCheck(_SetDecompressCallback(Handle, CallbackFunc, CallbackFreq));
  641. end;
  642.  
  643. procedure TFIFDecodeSession.SetFIFBuffer( Buffer: Pointer; Size: Longint);
  644. begin
  645.   FIFCheck(_SetFIFBuffer(Handle, Buffer, Size));
  646. end;
  647.  
  648. procedure TFIFDecodeSession.SetFTTBuffer( Buffer: Pointer; Size: Longint );
  649. begin
  650.   FIFCheck(_SetFTTBuffer(Handle, Buffer, Size));
  651. end;
  652.  
  653. procedure TFIFDecodeSession.SetOutputColorTable( ColorTable: Pointer; EntryInfo: Pointer;
  654.   NumColors: Longint );
  655. begin
  656.   FIFCheck(_SetOutputColorTable(FHandle, ColorTable, EntryInfo, NumColors));
  657. end;
  658.  
  659. procedure TFIFDecodeSession.SetOutputDither(Value: Boolean);
  660. begin
  661.   FIFCheck(_SetOutputDither(FHandle, Value));
  662. end;
  663.  
  664. procedure TFIFDecodeSession.SetOutputFilter(Value: Boolean);
  665. begin
  666.   FIFCheck(_SetOutputFilter(FHandle, Value));
  667. end;
  668.  
  669. procedure TFIFDecodeSession.SetOutputFormat( ColorPlane0, ColorPlane1, ColorPlane2,
  670.   ColorPlane3, RowOrder: Longint );
  671. begin
  672.   FIFCheck(_SetOutputFormat(Handle, ColorPlane0, ColorPlane1, ColorPlane2,
  673.     ColorPlane3, RowOrder));
  674. end;
  675.  
  676. procedure TFIFDecodeSession.SetOutputResolution( PixelWidth, PixelHeight: Longint );
  677. begin
  678.   FIFCheck(_SetOutputResolution(Handle, PixelWidth, PixelHeight));
  679. end;
  680.  
  681. procedure TFIFDecodeSession.SetProgressiveFIFBuffer( Buffer: Pointer;
  682.   Size: Longint; var InputStatus, HeaderLength: Longint );
  683. begin
  684.   FIFCheck(_SetProgressiveFIFBuffer(FHandle, Buffer, Size, InputStatus,
  685.     HeaderLength));
  686. end;
  687.  
  688. procedure TFIFDecodeSession.SetProgressiveStep( StepNumber: Longint );
  689. begin
  690.   FIFCheck(_SetProgressiveStep(FHandle, StepNumber));
  691. end;
  692.  
  693. procedure TFIFDecodeSession.StartProgressiveDecompression( ImageBuffer: Pointer;
  694.   CropPixelX, CropPixelY, CropPixelWidth, CropPixelHeight,
  695.   BytesPerRow, Expand: Longint );
  696. begin
  697.   FIFCheck(_StartProgressiveDecompression(Handle, ImageBuffer, CropPixelX,
  698.     CropPixelY, CropPixelWidth, CropPixelHeight, BytesPerRow, Expand));
  699. end;
  700.  
  701. class function TFIFDecodeSession.TestIfFIF( Buffer: Pointer; Length: Longint): Boolean;
  702. begin  // DECO_FIF_FUTURE_VERSION error will raise exception later in decoding
  703.   Result := False;
  704.   if LoadFIFDecodeLibrary('', False) then
  705.     _TestIfFIF(Buffer, Length, Result);
  706. end;
  707.  
  708.  
  709.  
  710. function LoadFIFDecodeLibrary(Filepath: string; RaiseExceptions: Boolean): Boolean;
  711.   procedure Error;
  712.   begin
  713.     raise EFIFError.CreateFmt('Error loading %s: (%d)',[FilePath, GetLastError])
  714.   end;
  715. var
  716.   Major, Minor: Longint;
  717. begin
  718.   Result := FIFDecodeLibraryHandle <> 0;
  719.   if Result then Exit;
  720.   Result := False;
  721.   if Length(Filepath) = 0 then
  722.     FilePath := FIFDecodeDLLName;
  723.   FIFDecodeLibraryHandle := LoadLibrary(PChar(Filepath));
  724.  
  725.   if FIFDecodeLibraryHandle = 0 then
  726.     if RaiseExceptions then Error else Exit;
  727.  
  728.   try
  729.     _GetDecoVersion := GetProcAddress(FIFDecodeLibraryHandle, 'GetDecoVersion');
  730.     if not Assigned(_GetDecoVersion) then
  731.       if RaiseExceptions then Error else Exit;
  732.  
  733.     _GetDecoVersion(Major, Minor);
  734.     if (Major < VERSION_PRIMARY) or
  735.       ((Major = VERSION_PRIMARY) and (Minor < VERSION_SECONDARY)) then
  736.       if RaiseExceptions then
  737.         raise EFIFError.CreateFmt('Wrong DLL version: %s %d.%d.  This program '+
  738.           'requires version %d.%d or later.',
  739.           [FilePath, Major, Minor, VERSION_PRIMARY, VERSION_SECONDARY])
  740.       else Exit;
  741.  
  742.     _ClearFIFBuffer := GetProcAddress(FIFDecodeLibraryHandle, 'ClearFIFBuffer');
  743.     _ClearFTTBuffer  := GetProcAddress(FIFDecodeLibraryHandle, 'ClearFTTBuffer');
  744.     _CloseDecompressor := GetProcAddress(FIFDecodeLibraryHandle, 'CloseDecompressor');
  745.     _DecompressToBuffer := GetProcAddress(FIFDecodeLibraryHandle, 'DecompressToBuffer');
  746.     _EndProgressiveDecompression := GetProcAddress(FIFDecodeLibraryHandle, 'EndProgressiveDecompression');
  747.     _GetColorTableFormat := GetProcAddress(FIFDecodeLibraryHandle, 'GetColorTableFormat');
  748.     _GetFastResolution := GetProcAddress(FIFDecodeLibraryHandle, 'GetFastResolution');
  749.     _GetFIFColorTable := GetProcAddress(FIFDecodeLibraryHandle, 'GetFIFColorTable');
  750.     _GetFIFFTTFileName := GetProcAddress(FIFDecodeLibraryHandle, 'GetFIFFTTFileName');
  751.     _GetFIFNumColors := GetProcAddress(FIFDecodeLibraryHandle, 'GetFIFNumColors');
  752.     _GetFIFNumSteps := GetProcAddress(FIFDecodeLibraryHandle, 'GetFIFNumSteps');
  753.     _GetOriginalResolution := GetProcAddress(FIFDecodeLibraryHandle, 'GetOriginalResolution');
  754.     _GetOutputColorTable := GetProcAddress(FIFDecodeLibraryHandle, 'GetOutputColorTable');
  755.     _GetOutputDither := GetProcAddress(FIFDecodeLibraryHandle, 'GetOutputDither');
  756.     _GetOutputFilter := GetProcAddress(FIFDecodeLibraryHandle, 'GetOutputFilter');
  757.     _GetOutputFormat := GetProcAddress(FIFDecodeLibraryHandle, 'GetOutputFormat');
  758.     _GetOutputResolution := GetProcAddress(FIFDecodeLibraryHandle, 'GetOutputResolution');
  759.     _GetPhysicalDimensions := GetProcAddress(FIFDecodeLibraryHandle, 'GetPhysicalDimensions');
  760.     _OpenDecompressor := GetProcAddress(FIFDecodeLibraryHandle, 'OpenDecompressor');
  761.     _ProgressiveDecompress := GetProcAddress(FIFDecodeLibraryHandle, 'ProgressiveDecompress');
  762.     _SetColorTableFormat := GetProcAddress(FIFDecodeLibraryHandle, 'SetColorTableFormat');
  763.     _SetDecompressCallback := GetProcAddress(FIFDecodeLibraryHandle, 'SetDecompressCallback');
  764.     _SetFIFBuffer := GetProcAddress(FIFDecodeLibraryHandle, 'SetFIFBuffer');
  765.     _SetFTTBuffer := GetProcAddress(FIFDecodeLibraryHandle, 'SetFTTBuffer');
  766.     _SetOutputColorTable := GetProcAddress(FIFDecodeLibraryHandle, 'SetOutputColorTable');
  767.     _SetOutputDither := GetProcAddress(FIFDecodeLibraryHandle, 'SetOutputDither');
  768.     _SetOutputFilter := GetProcAddress(FIFDecodeLibraryHandle, 'SetOutputFilter');
  769.     _SetOutputFormat := GetProcAddress(FIFDecodeLibraryHandle, 'SetOutputFormat');
  770.     _SetOutputResolution := GetProcAddress(FIFDecodeLibraryHandle, 'SetOutputResolution');
  771.     _SetProgressiveFIFBuffer := GetProcAddress(FIFDecodeLibraryHandle, 'SetProgressiveFIFBuffer');
  772.     _SetProgressiveStep := GetProcAddress(FIFDecodeLibraryHandle, 'SetProgressiveStep');
  773.     _StartProgressiveDecompression := GetProcAddress(FIFDecodeLibraryHandle, 'StartProgressiveDecompression');
  774.     _TestIfFIF := GetProcAddress(FIFDecodeLibraryHandle, 'TestIfFIF');
  775.     Result := FIFDecodeLibraryHandle <> 0;
  776.   finally
  777.     if not Result and (FIFDecodeLibraryHandle <> 0) then
  778.       UnloadFIFDecodeLibrary;
  779.   end;
  780. end;
  781.  
  782. procedure UnloadFIFDecodeLibrary;
  783. begin
  784.   if (FIFDecodeLibraryHandle <> 0) and (SessionCount = 0) then
  785.     FreeLibrary(FIFDecodeLibraryHandle);
  786.   FIFDecodeLibraryHandle := 0;
  787. end;
  788.  
  789. initialization
  790. finalization
  791.   UnloadFIFDecodeLibrary;
  792. end.
  793.  
  794.  
  795.