add very basic Format80 encoder

This commit is contained in:
Chris Forbes
2011-01-01 09:27:39 +13:00
parent 119b0c063d
commit cf2ad68a7c

View File

@@ -35,6 +35,8 @@ namespace OpenRA.FileFormats
Array.Copy(src, this.offset, dest, offset, count); Array.Copy(src, this.offset, dest, offset, count);
this.offset += count; this.offset += count;
} }
public int Remaining() { return src.Length - offset; }
} }
public static class Format80 public static class Format80
@@ -121,5 +123,25 @@ namespace OpenRA.FileFormats
} }
} }
} }
public static int EncodeInto(byte[] src, byte[] dest)
{
/* quick & dirty format80 encoder -- only uses raw copy operator, terminated with a zero-run. */
/* this does not produce good compression, but it's valid format80 */
var destIndex = 0;
var ctx = new FastByteReader(src);
do
{
var len = Math.Min(ctx.Remaining(), 0x3F);
dest[destIndex++] = (byte)(0x80 | len);
if (len > 0)
ctx.CopyTo(dest, destIndex, len);
}
while (!ctx.Done());
return destIndex;
}
} }
} }