anchor.diff:  end;
   
   
  -procedure TKMSpritePackEdit.SaveToRXXFile(const aFileName: string);
  -var
  -  I: Integer;
  -  InputStream: TMemoryStream;
  +procedure TKMSpritePackEdit.SaveToRXAFile(const aFileName: string);
  +var
  +  I, K, Count: Integer;
  +  SAT: TSpriteAtlasType;
  +  InputStream: TKMemoryStreamBinary;
     OutputStream: TFileStream;
     CompressionStream: TCompressionStream;
  -begin
  -  // No image was loaded yet
  -  //@Rey: Perhaps we should erase the file in such case, otherwise mapmaker will have to go into folder to delete rxx himself if he decided to "clear" it
  +  baseRAM, idealRAM, colorRAM, texCount: Cardinal;
  +begin
     if IsEmpty then Exit;
   
  +  MakeGFX_BinPacking(tfRGBA8, 1, baseRAM, colorRAM, texCount, False, nil);
  +
     ForceDirectories(ExtractFilePath(aFileName));
   
  -  InputStream := TMemoryStream.Create;
  -
  -  InputStream.Write(fRXData.Count, 4);
  +  InputStream := TKMemoryStreamBinary.Create;
  +
  +  //Sprite info
  +  InputStream.Write(fRXData.Count);
     InputStream.Write(fRXData.Flag[1], fRXData.Count);
   
     for I := 1 to fRXData.Count do
       if fRXData.Flag[I] = 1 then
       begin
  -      InputStream.Write(fRXData.Size[I].X, 4);
  -      InputStream.Write(fRXData.Pivot[I].X, 8);
  -
  +      InputStream.Write(fRXData.Size[I].X);
  +      InputStream.Write(fRXData.Size[I].Y);
  +      InputStream.Write(fRXData.Pivot[I].X);
  +      InputStream.Write(fRXData.Pivot[I].Y);
         if fRT = rxUnits then
           InputStream.Write(fRXData.SizeNoShadow[I].left, 16);
  -      InputStream.Write(fRXData.RGBA[I, 0], 4 * fRXData.Size[I].X * fRXData.Size[I].Y);
  -      InputStream.Write(fRXData.HasMask[I], 1);
  -      if fRXData.HasMask[I] then
  -        InputStream.Write(fRXData.Mask[I, 0], fRXData.Size[I].X * fRXData.Size[I].Y);
  -    end;
  +      InputStream.Write(fRXData.HasMask[I]);
  +    end;
  +
  +  //Atlases
  +  for SAT := Low(TSpriteAtlasType) to High(TSpriteAtlasType) do
  +  begin
  +    Count := Length(fGFXPrepData[SAT]);
  +    InputStream.Write(Count);
  +    for I := Low(fGFXPrepData[SAT]) to High(fGFXPrepData[SAT]) do
  +      with fGFXPrepData[SAT, I] do
  +      begin
  +        InputStream.Write(SpriteInfo.Width);
  +        InputStream.Write(SpriteInfo.Height);
  +        Count := Length(SpriteInfo.Sprites);
  +        InputStream.Write(Count);
  +        for K := Low(SpriteInfo.Sprites) to High(SpriteInfo.Sprites) do
  +        begin
  +          InputStream.Write(SpriteInfo.Sprites[K].SpriteID);
  +          InputStream.Write(SpriteInfo.Sprites[K].PosX);
  +          InputStream.Write(SpriteInfo.Sprites[K].PosY);
  +        end;
  +        InputStream.Write(TexType, SizeOf(TTexFormat));
  +        InputStream.Write(Data[0], Length(Data)*SizeOf(Data[0]));
  +      end;
  +  end;
  +
     OutputStream := TFileStream.Create(aFileName, fmCreate);
     CompressionStream := TCompressionStream.Create(clMax, OutputStream);
     InputStream.Position := 0;
  
positive.code:   KM_SoftShadows,
    KM_ResTypes,
    KM_PNG,
    KM_CommonTypes;
  
  
  var
  
negative.code:     procedure LoadFromRXFile(const aFileName: string);
      procedure LoadFromFolder(const aFolder: string);
      procedure SaveToRXXFile(const aFileName: string);
      procedure SaveToRXAFile(const aFileName: string);
      function TrimSprites: Cardinal; //For debug
      procedure ClearTemp; override;
      procedure GetImageToBitmap(aIndex: Integer; aBmp, aMask: TBitmap);
  