显示HN:SplatHash – BlurHash和ThumbHash的轻量级替代方案
Show HN: SplatHash – A lightweight alternative to BlurHash and ThumbHash

原始链接: https://github.com/junevm/splathash

SplatHash 是一种新的图像哈希算法,旨在实现速度和一致性。它将图像编码为固定的 16 字节(22 个字符的 base64url)哈希,能够实现非常快速的解码——仅需 0.067 毫秒即可生成 32x32 预览图。重要的是,SplatHash 在 Go、TypeScript 和 Python 实现中产生逐位相同的哈希值,Go 作为参考实现。 与 ThumbHash 和 BlurHash 等替代方案相比,SplatHash 在解码速度和内存分配方面明显优于它们。基准测试表明,SplatHash 的解码速度大约比 BlurHash 快 30 倍,并且使用的内存更少。 主要特性包括固定输出大小、使用 Oklab 颜色空间、空间局部化基函数(高斯函数)以及通过岭回归进行全局权重优化。它支持 alpha 通道,并设计为优先考虑解码性能,这对于诸如在每次页面加载时显示预览图之类的应用至关重要。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Show HN: SplatHash – 一个轻量级的 BlurHash 和 ThumbHash 替代方案 (github.com/junevm) 7 分,由 unsorted2270 发表于 1 小时前 | 隐藏 | 过去 | 收藏 | 讨论 大家好, 我构建了 SplatHash。它是一个轻量级的图像占位符生成器,我编写它是为了成为 BlurHash 和 ThumbHash 的一个更简单、更快的替代方案。 仓库:https://github.com/junevm/splathash 帮助 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系方式 搜索:
相关文章

原文

SplatHash encodes any image into exactly 16 bytes (a 22-char base64url string) and decodes it back to a 32×32 blurry preview in 0.067 ms. Go, TypeScript, and Python all produce bit-for-bit identical hashes.

Visual comparison of SplatHash, ThumbHash, and BlurHash reconstructions

Columns: original · SplatHash 32×32 · ThumbHash · BlurHash. Regenerate: mise run compare.

Go is the reference implementation. All others are verified bit-for-bit against it.

Go benchmarks on Intel Core i5-9300H (go test -bench=. -benchmem).

SplatHash ThumbHash BlurHash
Decode 0.067 ms 0.50 ms 6.55 ms
Encode 3.53 ms 0.86 ms 445 ms
Decode allocs 7 1,168 5
Bytes 16 fixed 25–37 20–25
String 22 chars 34–50 chars 27–30 chars

Decode runs on every page load for every user. Encode runs once at upload. Optimize for decode.

Raw output
BenchmarkEncodeSplatHash-8      303      3530083 ns/op   100760 B/op   29 allocs/op
BenchmarkEncodeThumbHash-8     1431       863553 ns/op     1015 B/op    6 allocs/op
BenchmarkEncodeBlurHash-8         3    445696421 ns/op 33358234 B/op    8 allocs/op
BenchmarkDecodeSplatHash-8    17182        67622 ns/op    29584 B/op    7 allocs/op
BenchmarkDecodeThumbHash-8     6559       503366 ns/op    58408 B/op 1168 allocs/op
BenchmarkDecodeBlurHash-8       171      6553100 ns/op   547552 B/op    5 allocs/op
Feature SplatHash ThumbHash BlurHash
Fixed output size Yes (16 bytes) No No
Storable as 128-bit integer Yes No No
Perceptual color space (Oklab) Yes No No
Spatially localized basis Yes (Gaussians) No No
Global weight optimization Yes (Ridge) No No
Alpha channel support Yes Yes No
Bit-exact cross-language parity Yes No No
Configurable quality vs. size No No Yes

Background color + six Gaussian blobs placed by matching pursuit, color-optimized by Ridge Regression, all in Oklab, packed into 128 bits. Full spec: ALGORITHM.md.

mise install     # install Go and Node at pinned versions
mise run test    # run all tests (Go + TypeScript + Python)
mise run bench   # Go benchmarks
mise run compare # regenerate docs/comparison.png

See LICENSE.

联系我们 contact @ memedata.com