,      .spr:

-    128 .      0.
-  4     06.   32     ,
    ,   .
-    RLE    .
-     0  16   .
-  16  17  ,     .spr  0.
-   18    .
-               ,
     .
-         ,   .
 .   N   ,    .
      N.  , N    1  128.
 .   ,   N .       128+N.
N    1  127.
-       , ,    ,
         .

   ,  :
//   .
fsize:=fsize-1; //      
while buf^[fsize]=0 do
fsize:=fsize-1;
cpos:=32767;
repeat
b:=buf^[fsize-1];
c:=buf^[fsize ]-1;
if c>=128 then begin //  .  "b" "c" 
c:=c and $7F;
if cpos-c >=0 then
for x:=0 to c do
spb^[cpos-x]:=b;
end else begin //  ,   "c" 
if (cpos-c >=0) and (fsize-c-1 >0) then
for x:=0 to c do
spb^[cpos-x]:=buf^[fsize-x-1];
fsize:=fsize-c; //      "" 
end;
cpos:=cpos-c-1; //      
fsize:=fsize-2; //       
until fsize<=18; 


   .    SrcCount    .    32768.   DestCount        .      .             128.

:

//     06
procedure PackVEC2SPRv1(SrcBuf:pbytearray; SrcCount:integer; DestBuf:pbytearray; var DestCount:integer);
var
  i:integer;
  b,ce,cne:byte;
  ob:word;
begin
  //   32   .     DestCount
  //       .     34048
  //         18+32768+259=33045 
  //     18   , ,     .

  //    18  DestCount (34047) 
  for i:=18 to DestCount-1 do begin
    DestBuf^[i]:=0;
  end;

  //  
  DestCount:=18;
  ce:=0;
  cne:=0;
//  ob:=SrcBuf^[0];
  ob:=256;
  for i:=0 to SrcCount-1 do begin
    b:=SrcBuf^[i];

    // .  1
    if b=ob then begin
      //    ,      ,  

      if cne>0 then begin // 2       0, 
        cne:=cne-1; //     1
        ce:=ce+1;   //      1
      end;

      if cne>0 then begin  //    >0     
        DestCount:=DestCount+cne;
        DestBuf^[DestCount]:=cne;
        repeat
          DestBuf^[DestCount-cne]:=SrcBuf^[i-cne-1];
          cne:=cne-1;
        until cne=0;
        DestCount:=DestCount+1;
      end;

      //    
      ce:=ce+1;
      if ce>=127 then begin //     >=127   
        DestBuf^[DestCount  ]:=b;
        DestBuf^[DestCount+1]:=ce+128;
        DestCount:=DestCount+2;
        ce:=0;
      end;
    end else begin
      if ce=1 then begin
        cne:=cne+1;
        ce:=0;
      end;
      if ce>1 then begin //     ,  
        DestBuf^[DestCount  ]:=ob;
        DestBuf^[DestCount+1]:=ce+128;
        DestCount:=DestCount+2;
        ce:=0;
      end;

      //   
      cne:=cne+1;
      if cne>=127 then begin  //    >= 127     
        DestCount:=DestCount+cne;
        DestBuf^[DestCount]:=cne;
        repeat
          DestBuf^[DestCount-cne]:=SrcBuf^[i-cne+1];
          cne:=cne-1;
        until cne=0;
        DestCount:=DestCount+1;
      end;
    end;{}
    ob:=b;
  end;

  //    
  if cne>0 then begin  //    >0     
    DestCount:=DestCount+cne;
    DestBuf^[DestCount]:=cne;
    repeat
      DestBuf^[DestCount-cne]:=SrcBuf^[SrcCount-cne+1];
      cne:=cne-1;
    until cne=0;
    DestCount:=DestCount+1;
  end;

  if ce>0 then begin //     ,  
    DestBuf^[DestCount  ]:=ob;
    DestBuf^[DestCount+1]:=ce+128;
    DestCount:=DestCount+2;
  end;

end;

