Decode color drag-pan cursor

This commit is contained in:
gamer147
2026-07-21 13:14:02 -04:00
parent 44bbf5b6b4
commit b0971f2047
5 changed files with 83 additions and 15 deletions

View File

@@ -22,7 +22,36 @@ public class CurDecoderTests
Assert.Contains(cursor.Image.Pixels.Where((_, i) => i % 4 == 3), alpha => alpha == 255);
}
[Fact]
public void HimegariPanCursor_DecodesFourBitPixelsAndHotspot()
{
var resources = ResourceMap.Load();
var entry = resources.ResolveCursor(0x32ce);
Assert.NotNull(entry);
Assert.Equal("CURSOR09.CUR", entry!.Name);
var cursor = resources.DecodeCursor(entry);
Assert.Equal(32, cursor.Image.Width);
Assert.Equal(32, cursor.Image.Height);
Assert.Equal(16, cursor.HotspotX);
Assert.Equal(14, cursor.HotspotY);
AssertPixel(cursor.Image, 0, 0, 0, 0, 0, 0);
AssertPixel(cursor.Image, 10, 10, 128, 128, 128, 255);
AssertPixel(cursor.Image, 12, 24, 0, 0, 128, 255);
}
[Fact]
public void TruncatedCursor_IsRejected()
=> Assert.Throws<InvalidDataException>(() => CurDecoder.Decode(new byte[21], "bad.cur"));
private static void AssertPixel(RgbaImage image, int x, int y,
byte r, byte g, byte b, byte a)
{
int offset = (y * image.Width + x) * 4;
Assert.Equal(r, image.Pixels[offset]);
Assert.Equal(g, image.Pixels[offset + 1]);
Assert.Equal(b, image.Pixels[offset + 2]);
Assert.Equal(a, image.Pixels[offset + 3]);
}
}