Sage-ST ä

Compress

Documentation

Global Declarations (Constants, Types, Variables)
Compress CompressBuffer CompressFile
UnCompress UnCompressBuffer UnCompressFile





  TYPE
    LoadBuffer = PROCEDURE (CONST SYSTEM.ADDRESS,    (* buffer *)
                            VAR CARDINAL);

    (* totalIn *)
    PutBuffer = PROCEDURE (CONST SYSTEM.ADDRESS,    (* buffer *)
                           CONST CARDINAL,          (* totalOut *)
                           VAR BOOLEAN);

    (* success *)




  PROCEDURE Compress
             (CONST compression  : CARDINAL;
              CONST workBuffer   : SYSTEM.ADDRESS;
              CONST workLength   : CARDINAL;
              CONST inputProc    : LoadBuffer;
              CONST outputProc   : PutBuffer;
              CONST showProgress : BOOLEAN;
              VAR   Status       : CARDINAL);

  (**
      Compress - Compress data from and to buffers.


      This procedure  begins the process  of compressing data.  The data
      compression method  used is a sliding  dictionary method to reduce
      repeated  byte sequences.  The size  of the  dictionary depends on
      compression factor. Valid compression factors are :

        1  -   512 byte buffer, minimum compression, least time
        2  -  1024 byte buffer, better compression, more time
        3  -  2048 byte buffer, better compression, more time
        4  -  4096 byte buffer, best compression, longest time

      Compression factors outside this range will default to a factor of
      2.

      "inputProc"  will  be  called  by  the  program  when more data is
      needed. The  user is required to  fill in the "Buffer"  to the the
      "totalIn" value  received from compress and  pass the total number
      of  bytes loaded  back in  "totalIn".  A  value of  zero will  end
      compress processing signaling the end of data.

      "outputProc" will be  called when there is no  room to output more
      data or at the conclusion of the program. "totalOut", the number of
      bytes in the output buffer, is  passed to you. Process this buffer
      as needed. When control is  passed back to the compression program
      data will again be written to the buffer from the first. "success"
      set to FALSE will indicate an error and processing will quit.

      CALLING SEQUENCE -

        Compress (compression, workBuffer, workLength,
                  inputProc, outputProc,
                  showProgress, status);

      ENTRY -

        compression : CARDINAL
          Compression factor (1 .. 4).

        workBuffer : SYSTEM.ADDRESS
          Address  of a  working buffer.   Must be  at least  four times
          bigger  than   the  search  buffer   size  indicated  by   the
          compression factor.

        workLength : CARDINAL
          Total length of workbuffer in bytes.

        inputProc : LoadBuffer
          Procedure to load buffer when needed;

        outputProc : PutBuffer
          Procedure to put buffer when needed;

        showProgress : BOOLEAN
          Show  a  device  (propeller)  which  indicates  compression in
          progress.

      EXIT -

        status : CARDINAL
          Number indicating the status of the compression result.
            0 - No error occurred
            4 - Error putting output buffer
            5 - Work buffer too small

      EXAMPLE -

        PROCEDURE LoadInput
                   (    buffer : SYSTEM.ADDRESS;
                    VAR totalIn : CARDINAL);
        BEGIN
          ReadData (buffer, totalIn);
        END LoadInput;

        PROCEDURE PutOutputBuffer
             (    buffer : SYSTEM.ADDRESS;
                  totalOut : CARDINAL;
              VAR success : BOOLEAN);

        BEGIN
          success := WriteData (buffer, totalOut);
        END PutOutput;


        PROCEDURE MyProgram;

        BEGIN
           .
           .
          Compress.Compress (compression, SYSTEM.ADR (workBuffer), workLength,
                            LoadInput, PutOutputBuffer,
                            showProgress, status);
           .
           .
        END MyProgram;
  *)




  PROCEDURE UnCompress
             (CONST workBuffer   : SYSTEM.ADDRESS;
              CONST workLength   : CARDINAL;
              CONST inputProc    : LoadBuffer;
              CONST outputProc   : PutBuffer;
              CONST showProgress : BOOLEAN;
              VAR   Status       : CARDINAL);

  (**
      UnCompress - Uncompress data from and to buffers.


      This procedure reverses the process  of compressing data. The data
      must have been compressed using this compression package.

      "inputProc"  will  be  called  by  the  program  when more data is
      needed. The user  is required to fill in the  buffer up to the the
      "totalIn" value  received from compress and  pass the total number
      of  bytes loaded  back in  "totalIn".  A  value of  zero will  end
      compress processing signaling the end of data.

      "outputProc" will be  called when there is no  room to output more
      data or  at the conclusion  of the program.  "totalOut", the total
      number of  bytes in the output  buffer, is passed to  you. Process
      this  buffer  as  needed.  When  control  is  passed  back  to the
      compression program data will again  be written to the buffer from
      the  first. "success"  set to   FALSE will  indicate an  error and
      processing will quit.

      CALLING SEQUENCE -

        Compress.UnCompress (workBuffer, workLength,
                             inputProc, outputProc,
                             showProgress, status);

      ENTRY -

        workBuffer : SYSTEM.ADDRESS
          Address  of a  working buffer.   Must be  at least  four times
          bigger  than   the  search  buffer   size  indicated  by   the
          compression factor used to compress the data.

        workLength : CARDINAL
          Total length of workbuffer in bytes.

        inputProc : LoadBuffer
          Procedure to load buffer when needed;

        outputProc : PutBuffer
          Procedure to put buffer when needed;

        showProgress : BOOLEAN
          Show  a  device  (propeller)  which  indicates  compression in
          progress.

      EXIT -

        status : CARDINAL
          Number indicating the status of the uncompression result.
            0 - No error occurred
            4 - Error putting output buffer
            5 - Work buffer too small

      EXAMPLE -

        PROCEDURE LoadInput
                   (    buffer : SYSTEM.ADDRESS;
                    VAR totalIn : CARDINAL);
        BEGIN
          ReadData (buffer, totalIn);
        END LoadInput;

        PROCEDURE PutOutputBuffer
                   (    buffer : SYSTEM.ADDRESS;
                        totalOut : CARDINAL;
                        success : BOOLEAN);

        BEGIN
          success := WriteData (buffer, totalOut);
        END PutOutput;

        PROCEDURE MyProgram;

        BEGIN
          .
          .
          Compress.UnCompress (workBuffer'address, workLength,
                              LoadInput, PutOutputBuffer,
                              showProgress, status);
          .
          .
        end MyProgram;
  *)




  PROCEDURE CompressBuffer
             (CONST compression  : CARDINAL;
              CONST inBuffer     : SYSTEM.ADDRESS;
              CONST inBufLength  : CARDINAL;
              CONST outBuffer    : SYSTEM.ADDRESS;
              CONST outBufLength : CARDINAL;
              CONST showProgress : BOOLEAN;
              VAR   resultLength : CARDINAL;
              VAR   Status       : CARDINAL);

  (**
      CompressBuffer - Compress a memory buffer.


      This routine will use the  Compress procedure to compress an input
      buffer and write the compressed data to an output buffer.

      The size  of the dictionary  depends on compression  factor. Valid
      compression factors are :

        1  -   512 byte buffer, minimum compression, least time
        2  -  1024 byte buffer, better compression, more time
        3  -  2048 byte buffer, better compression, more time
        4  -  4096 byte buffer, best compression, longest time

      Compression factors outside this range will default to a factor of
      2.

      CALLING SEQUENCE -

        CompressBuffer (compression,
                        inBuffer, inBufLength,
                        outBuffer, outBufLength,
                        showProgress,
                        resultLength, status);

      ENTRY -

        compression : CARDINAL
          Compression factor (1 .. 4).

        inBuffer : SYSTEM.ADDRESS
          Address  of  the  buffer  containing  the  input  data  to  be
          compressed.

        inBufLength : CARDINAL
          Length of the input buffer;

        outBuffer : SYSTEM.ADDRESS
          Address of the buffer where compressed input buffer data is
          to be stored.

        outBufLength : CARDINAL
          Length of the output buffer;

        showProgress : BOOLEAN
          Show a device (propeller) which indicates compression in
          progress.

        resultLength : CARDINAL
          The valid length of the resluting compressed data stored in
          the output buffer.

      EXIT -

        status : CARDINAL
          Number indicating the status of the compression result.
            0 - No error occurred
            4 - Error putting output buffer
            5 - Work buffer too small
  *)




  PROCEDURE UnCompressBuffer
             (CONST inBuffer     : SYSTEM.ADDRESS;
              CONST inBufLength  : CARDINAL;
              CONST outBuffer    : SYSTEM.ADDRESS;
              CONST outBufLength : CARDINAL;
              CONST showProgress : BOOLEAN;
              VAR   resultLength : CARDINAL;
              VAR   Status       : CARDINAL);

  (**
      UnCompressBuffer - Uncompress a memory buffer.


      This routine  will use the  Uncompress procedure to  uncompress an
      input buffer and write the uncompressed data to an output buffer.

      This procedure reverses the process  of compressing data. The data
      must have been compressed using this compression package.

      CALLING SEQUENCE -

        UnCompressBuffer (inBuffer, inBufLength,
                          outBuffer, outBufLength,
                          showProgress,
                          resultLength, status);

      ENTRY -

        inBuffer : SYSTEM.ADDRESS
          Address  of  the  buffer  containing  the  input  data  to  be
          uncompressed.

        inBufLength : CARDINAL
          Length of the input buffer.

        outBuffer : SYSTEM.ADDRESS
          Address of the buffer where uncompressed input buffer data is
          to be stored.

        outBufLength : CARDINAL
          Length of the output buffer.

        showProgress : BOOLEAN
          Show a device (propeller) which indicates compression in
          progress.

      EXIT -

        resultLength : CARDINAL
          The valid length of the resluting compressed data stored in
          the output buffer.

        status : CARDINAL
          Number indicating the status of the uncompression result.
            0 - No error occurred
            4 - Error putting output buffer
            5 - Work buffer too small
  *)




  PROCEDURE CompressFile
             (CONST fileIn       : ARRAY OF CHAR;
              CONST fileOut      : ARRAY OF CHAR;
              CONST compression  : CARDINAL;
              CONST showProgress : BOOLEAN;
              VAR   bytesIn      : ModSys.INT32;
              VAR   bytesOut     : ModSys.INT32;
              VAR   Status       : CARDINAL);

  (**
      CompressFile - Compress a DOS file to another file.


      This routine will use the Compress procedure, read the input file,
      compress the data and write the compressed data to another file.

      CALLING SEQUENCE -

        CompressFile (fileIn, fileOut, compression,
                      bytesIn, bytesOut, status);

      ENTRY -

        fileIn : ARRAY OF CHAR
          File  name of  file to  be compressed.  Must include  any path
          information if needed.

        fileOut : ARRAY OF CHAR
          File  name  of  the  comressed  file.  Must  include  any path
          information if needed. The compressed  file cannot be the same
          as  the input  file name.  The file  is tagged  with a special
          sequence  of characters  to indicate  that it  is a compressed
          file and the compression used.

        compression : CARDINAL
          Compression factor (1 .. 4); (See Compress for info).

        showProgress : BOOLEAN
          Show  a  device  (propeller)  which  indicates  compression in
          progress.

      EXIT -

        bytesIn : ModSys.INT32
          Number of bytes compressed from the input file. (File size)

        bytesOut : ModSys.INT32
          Number of  bytes in the  compressed file. A  compression ratio
          can be calculated from this information.

        status : CARDINAL
          Number indicating the status of the compression result.
            0 - No error occurred
            1 - Could not open input file
            2 - Could not open output file
            4 - Error putting output buffer
            5 - Work buffer too small
  *)




  PROCEDURE UnCompressFile
             (CONST fileIn       : ARRAY OF CHAR;
              CONST fileOut      : ARRAY OF CHAR;
              CONST showProgress : BOOLEAN;
              VAR   Status       : CARDINAL);

  (**
      UnCompressFile - Uncompress a compressed file to another file.


      This  routine will  use the  UnCompress procedure,  read the input
      compressed file,  uncompress the data  and write the  uncompressed
      data to another file.

      CALLING SEQUENCE -

        UnCompressFile (fileIn, fileOut, status);

      ENTRY -

        fileIn : ARRAY OF CHAR
          File name  of file to  be uncompressed. Must  include any path
          information  if needed.  The file  must be  a file  compressed
          using the CompressFile routine above.

        fileOut : ARRAY OF CHAR
          File  name  of  the  uncomressed  file.  Must include any path
          information if needed.

        showProgress : BOOLEAN
          Show  a  device  (propeller)  which  indicates  compression in
          progress.

      EXIT -

        status : CARDINAL
          Number indicating the status of the uncompression result.
            0 - No error occurred
            1 - Could not open input file
            2 - Could not open output file
            3 - Not a compressed file
            4 - Error putting output buffer
            5 - Work buffer too small
  *)




Send mail to   warren.merrill@inl.gov with questions or comments about this web site.
Copyright © 1989-2006 Battelle Energy Alliance