The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



Decode


Unit:SDL_dstruct
Class: TRLEncoder
Declaration: function Decode (InByte: byte): boolean;

The function Decode decodes a RL encoded data stream. The user has to input the next byte of the encoded stream. Decode returns TRUE, if the internal buffer contains any decoded data. Please note that the length of the buffer has to be equal or larger than the length of the buffer when the data has been encoded.

Below is a sample code for decoding an RL encoded file (RLE1 is an instance of TRLEncoder):

 
const 
  BLeng = 1024; 

var 
  IFile     : file; 
  OFile     : file; 
  count     : integer; 
  Buffer    : array [1..BLeng] of byte; 
  OutBuffer : array [1..BLeng] of byte; 
  i         : integer; 

begin 
OpenDialog1.FileName := '*.rle'; 
if OPenDialog1.Execute then 
  begin 
  assignFile (IFile, OpenDialog1.Filename); 
  reset (IFile, 1); 
  assignFile (OFile, StripExtension(OpenDialog1.Filename)+'.BM2'); 
  rewrite (OFile, 1); 
  RLE1.Reset; 
  RLE1.BufLeng := BLeng; 
  while not eof(IFile) do 
    begin 
    Blockread (IFile, Buffer, BLeng, count); 
    for i:=1 to count do 
      if RLE1.Decode (Buffer[i]) then 
        begin 
        RLE1.GetResult (OutBuffer); 
        BlockWrite (OFile, OutBuffer, BLeng); 
        end; 
    end; 
  count := RLE1.Finish (OutBuffer); 
  BlockWrite (OFile, OutBuffer, count); 
  closeFile (OFile); 
  closeFile (IFile); 
  end; 
end; 


Last Update: 2012-Oct-20