SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. procedure RLE_Compression (FileName, RLEFileName: String);
  2. var
  3.   count, value, pref, x, i: byte;
  4. begin
  5.   pref := Min(FileName);
  6.   AssignFile(File_in, FileName);
  7.   Reset(File_in);
  8.   AssignFile(File_out, RLEFileName);
  9.   Rewrite(File_out);
  10.   Write(File_out, pref);
  11.  
  12.   count:=0;
  13.   while not eof(file_in) do begin
  14.     read(file_in, x);
  15.     if count = 0 then begin
  16.       value := x;
  17.     end;
  18.     if (value = x) and (count < 255) then begin
  19.       inc(count);
  20.     end else begin
  21.       if count <= 2 then begin
  22.         if value <> pref then begin
  23.           for i := 1 to count do Write(File_Out, value);
  24.         end
  25.         else begin
  26.           Write(File_Out, pref, count);
  27.         end;
  28.       end else begin
  29.         Write(File_Out, pref, count, value);
  30.       end;
  31.       count := 1;
  32.       value := x;
  33.     end;
  34.   end;
  35.     if count <= 2 then begin
  36.       if value <> pref then begin
  37.         for i := 1 to count do Write(File_Out, value);
  38.       end
  39.       else begin
  40.         Write(File_Out, pref, count);
  41.       end;
  42.     end else begin
  43.       Write(File_Out, pref, count, value);
  44.     end;
  45.  
  46.  
  47.  
  48. procedure RLE_Uncompression(RLEFileName, FileName: string);
  49. var
  50.   count, value, pref, i: byte;
  51. begin
  52.   AssignFile(File_in, RLEFileName);
  53.   Reset(File_in);
  54.   AssignFile(File_out, FileName);
  55.   Rewrite(File_out);
  56.   Read(File_In, pref);
  57.  
  58.   while not eof(File_in) do begin
  59.     Read(File_in, value);
  60.     if value = pref then begin
  61.       Read(File_in, count);
  62.       if count > 2 then begin
  63.         Read(file_in, value);
  64.         for i := 1 to count do begin
  65.           Write(File_out, value);
  66.         end;
  67.       end else begin
  68.         for i := 1 to count do begin
  69.           Write(File_out, pref);
  70.         end;
  71.       end;
  72.     end else Write(file_out, value);
  73.   end;
  74.  
  75.   CloseFile(File_in);
  76.   CloseFile(File_out);
  77. end;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top