chore: bootstrap repository foundation
Solution layout, build rules with zero-package guard, in-house test framework, localization runtime, brand mark rasteriser with ICO/PNG generation, Core contracts (imaging, video, domain model, TIFF reader), Titano.Tools (make-icon, i18n, xaml-lint, package-guard) and docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
109 files changed
+7523
No files matched your search
@@ -0,0 +1,47 @@
|
||||
namespace Titano.Core.Hashing;
|
||||
|
||||
/// <summary>CRC-32 (IEEE 802.3, reflected 0xEDB88320) as used by PNG, ZIP and gzip. Slicing-by-8.</summary>
|
||||
public sealed class Crc32
|
||||
{
|
||||
private static readonly uint[] Table = BuildTable();
|
||||
private uint _crc = 0xFFFFFFFFu;
|
||||
|
||||
public void Append(ReadOnlySpan<byte> data) => _crc = Update(_crc, data);
|
||||
|
||||
public uint GetCurrentHashAsUInt32() => ~_crc;
|
||||
|
||||
public void Reset() => _crc = 0xFFFFFFFFu;
|
||||
|
||||
public static uint Compute(ReadOnlySpan<byte> data) => ~Update(0xFFFFFFFFu, data);
|
||||
|
||||
private static uint Update(uint crc, ReadOnlySpan<byte> data)
|
||||
{
|
||||
var t = Table;
|
||||
var i = 0;
|
||||
for (; i + 8 <= data.Length; i += 8)
|
||||
{
|
||||
var one = (uint)(data[i] | data[i + 1] << 8 | data[i + 2] << 16 | data[i + 3] << 24) ^ crc;
|
||||
var two = (uint)(data[i + 4] | data[i + 5] << 8 | data[i + 6] << 16 | data[i + 7] << 24);
|
||||
crc = t[7 * 256 + (one & 0xFF)] ^ t[6 * 256 + ((one >> 8) & 0xFF)] ^ t[5 * 256 + ((one >> 16) & 0xFF)] ^ t[4 * 256 + (one >> 24)]
|
||||
^ t[3 * 256 + (two & 0xFF)] ^ t[2 * 256 + ((two >> 8) & 0xFF)] ^ t[256 + ((two >> 16) & 0xFF)] ^ t[two >> 24];
|
||||
}
|
||||
for (; i < data.Length; i++) crc = t[(crc ^ data[i]) & 0xFF] ^ (crc >> 8);
|
||||
return crc;
|
||||
}
|
||||
|
||||
private static uint[] BuildTable()
|
||||
{
|
||||
var t = new uint[8 * 256];
|
||||
for (uint n = 0; n < 256; n++)
|
||||
{
|
||||
var c = n;
|
||||
for (var k = 0; k < 8; k++) c = (c & 1) != 0 ? 0xEDB88320u ^ (c >> 1) : c >> 1;
|
||||
t[n] = c;
|
||||
}
|
||||
for (var s = 1; s < 8; s++)
|
||||
{
|
||||
for (var n = 0; n < 256; n++) t[s * 256 + n] = t[(s - 1) * 256 + n] >> 8 ^ t[t[(s - 1) * 256 + n] & 0xFF];
|
||||
}
|
||||
return t;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user