diff --git a/ABSpriteEditor/ABSpriteEditor/Sprites/IO/SpriteCompression.cs b/ABSpriteEditor/ABSpriteEditor/Sprites/IO/SpriteCompression.cs index dd41a2f..3ec64e7 100644 --- a/ABSpriteEditor/ABSpriteEditor/Sprites/IO/SpriteCompression.cs +++ b/ABSpriteEditor/ABSpriteEditor/Sprites/IO/SpriteCompression.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Drawing; // @@ -32,12 +33,20 @@ public static IEnumerable EnumerateCompressedMaskBytes(Bitmap bitmap) } private static IEnumerable EnumerateCompressedBytes(Bitmap bitmap, IEnumerable bytes) + { + if ((bitmap.Width < 1) || (bitmap.Height < 1)) + throw new ArgumentException("bitmap must be at least 1x1"); + + return EnumerateCompressedBytes(bitmap.GetPixel(0, 0), bytes); + } + + private static IEnumerable EnumerateCompressedBytes(Color firstPixel, IEnumerable bytes) { var writer = new BitWriter(); - writer.WriteBit(bitmap.GetPixel(0, 0) == Color.White); + writer.WriteBit(firstPixel.ToArgb() == SpriteColours.White.ToArgb()); - foreach (var span in bytes) + foreach (var span in GenerateBitSpans(bytes)) { WriteCompressedLength(writer, span - 1); }