Make image hashing deterministic and format/DPI-agnostic

Merged
BE
6mo ago
+41-12

Closes #4116


Summary by cubic

Makes image hashing deterministic and format/DPI-agnostic by normalizing to Pbgra32 and hashing raw pixels. Prevents collisions across formats/metadata and reduces allocations.

  • Summary of changes
    • Changed: Hash raw Pbgra32 pixels via SHA1.HashData instead of JPEG-encoded buffers.
    • Changed: Only accept BitmapSource inputs with IsFrozen; others return null.
    • Added: Normalize to Pbgra32, freeze the converted bitmap, guard zero-size images, and use ArrayPool<byte> for pixel storage.
    • Removed: MemoryStream, JpegBitmapEncoder, BitmapFrame, and any reliance on encoder output or metadata (including DPI/EXIF).
    • Memory: Rents a width×height×4 buffer from ArrayPool<byte>, returns it after use to avoid LOH allocations and reduce GC pressure.
    • Security: No new risks; SHA‑1 used only for IDs, pooled buffers are returned and not exposed.
    • Tests: No unit tests added.