{"_id":"@4bitlabs/ssim","_rev":"2-b66a63639966861a2b9b339abf41cefe","name":"@4bitlabs/ssim","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@4bitlabs/ssim","version":"1.0.0","keywords":["compare","image","similarity","ssim","typescript"],"author":{"url":"j.holmes.codes","name":"J. Holmes","email":"j@holmes.codes"},"license":"MIT","_id":"@4bitlabs/ssim@1.0.0","maintainers":[{"name":"32bitkid","email":"32bitkid@gmail.com"}],"homepage":"https://github.com/32bitkid/4bitlabs.ssim","bugs":{"url":"https://github.com/32bitkid/4bitlabs.ssim/issues"},"dist":{"shasum":"ae0b54ddefed66b02db811b7cfdc65ae2314850a","tarball":"https://registry.npmjs.org/@4bitlabs/ssim/-/ssim-1.0.0.tgz","fileCount":7,"integrity":"sha512-MTot71UmdgRozQBKK3OZCYgjoZ5680qOCyadoNlyv9vCNrFvZTI/y9EdsY4VEqCB/QMdCYS4Zae/f1QYs9ZjFg==","signatures":[{"sig":"MEYCIQDrwvYcXdIBwLquLT8xInJcO2n3dj4Ck/xcIa0ZWi9LXwIhALFJvwkj1Gss+znLwdF3HE+qKpB0v7tKO0L/o2vS/7sX","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":27336},"type":"module","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"621547c75cf2431b2acee01b0837b436f1b065df","scripts":{"lint":"biome check","test":"vitest run","bench":"vitest bench","build":"tsdown"},"_npmUser":{"name":"32bitkid","email":"32bitkid@gmail.com"},"repository":{"url":"git+https://github.com/32bitkid/4bitlabs.ssim.git","type":"git"},"_npmVersion":"12.0.1","description":"[![License][license]][npm] [![NPM Version][version]][npm] [![NPM Downloads][dl]][npm] [![Ko-fi][kofibadge]][kofi]","directories":{},"_nodeVersion":"22.23.1","allowScripts":{"fsevents@2.3.3":true},"dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"tsdown":"^0.22.12","vitest":"^4.1.10","fast-png":"^8.0.0","pure-rand":"^8.4.2","image-ssim":"^0.2.0","typescript":"^6.0.3","@types/node":"^26.1.1","@biomejs/biome":"^2.5.4"},"_npmOperationalInternal":{"tmp":"tmp/ssim_1.0.0_1785945731238_0.6743862800050442","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@4bitlabs/ssim","version":"1.0.1","keywords":["compare","image","ImageData","similarity","ssim","typescript"],"homepage":"https://github.com/32bitkid/4bitlabs.ssim","bugs":{"url":"https://github.com/32bitkid/4bitlabs.ssim/issues"},"repository":{"type":"git","url":"git+https://github.com/32bitkid/4bitlabs.ssim.git"},"license":"MIT","author":{"name":"J. Holmes","email":"j@holmes.codes","url":"https://j.holmes.codes"},"type":"module","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"bench":"vitest bench","build":"tsdown","lint":"biome check","test":"vitest run"},"dependencies":{},"devDependencies":{"@biomejs/biome":"^2.5.4","@types/node":"^26.1.1","fast-png":"^8.0.0","image-ssim":"^0.2.0","pure-rand":"^8.4.2","tsdown":"^0.22.12","typescript":"^6.0.3","vitest":"^4.1.10"},"allowScripts":{"fsevents@2.3.3":true},"gitHead":"767273d2e0e5620595d338bd588b440024082858","_id":"@4bitlabs/ssim@1.0.1","description":"[![License][license]][npm] [![NPM Version][version]][npm] [![NPM Downloads][dl]][npm] [![Ko-fi][kofibadge]][kofi]","_nodeVersion":"22.23.1","_npmVersion":"12.0.1","dist":{"integrity":"sha512-P9wnOiKMhvMzEzCQmmOQbKALkA5us6AHgFH/j/0IRXodgD7SmoRztjHu0KnJQo/dbLm2at59wAgOudARowyWWQ==","shasum":"df2f04f7cc19b3ba033e952a7c6d5ef35206693c","tarball":"https://registry.npmjs.org/@4bitlabs/ssim/-/ssim-1.0.1.tgz","fileCount":7,"unpackedSize":27361,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCIXTj+l98OJQundIX9dZzFXAOjOyGEnXBQVnrwqMsfXgIgB03vEXcrCBfGbAdkBCltrb2YG4DHZtbQIhc1cnJW++8="}]},"_npmUser":{"name":"32bitkid","email":"32bitkid@gmail.com"},"directories":{},"maintainers":[{"name":"32bitkid","email":"32bitkid@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ssim_1.0.1_1786463498728_0.9458555286128401"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-05T16:02:10.986Z","modified":"2026-08-11T15:51:39.055Z","1.0.0":"2026-08-05T16:02:11.436Z","1.0.1":"2026-08-11T15:51:38.860Z"},"bugs":{"url":"https://github.com/32bitkid/4bitlabs.ssim/issues"},"author":{"name":"J. Holmes","email":"j@holmes.codes","url":"https://j.holmes.codes"},"license":"MIT","homepage":"https://github.com/32bitkid/4bitlabs.ssim","keywords":["compare","image","ImageData","similarity","ssim","typescript"],"repository":{"type":"git","url":"git+https://github.com/32bitkid/4bitlabs.ssim.git"},"description":"[![License][license]][npm] [![NPM Version][version]][npm] [![NPM Downloads][dl]][npm] [![Ko-fi][kofibadge]][kofi]","maintainers":[{"name":"32bitkid","email":"32bitkid@gmail.com"}],"readme":"# @4bitlabs/dct\n\n[![License][license]][npm]\n[![NPM Version][version]][npm]\n[![NPM Downloads][dl]][npm]\n[![Ko-fi][kofibadge]][kofi]\n\n[npm]: https://www.npmjs.com/package/@4bitlabs/ssim\n[version]: https://img.shields.io/npm/v/%404bitlabs%2Fssim\n[license]: https://img.shields.io/npm/l/%404bitlabs%2Fssim\n[dl]: https://img.shields.io/npm/dy/%404bitlabs%2Fssim\n[kofibadge]: https://shields.io/badge/ko--fi-donate-ff5f5f?logo=ko-fi&style=for-the-badgeKo-fi\n[kofi]: https://ko-fi.com/thirtytwo\n\nImage structural similarity (SSIM) in ESM for browser/server with some performance improvements.\n\nAdapted from [darosh/image-ssim-js][refimpl] with some performance optimizations and usability changes.\n\nAlso see:\n- https://github.com/ibezkrovnyi/image-quantization/blob/9f62/src/quality/ssim.ts\n- https://github.com/rhys-e/structural-similarity\n- http://en.wikipedia.org/wiki/Structural_similarity\n\n## Changes from the original\n\nThis implementation largely follows the original implementation, and does verify that it returns the same values\nfor the same comparisons as the original. However, there are some significant changes to be aware of:\n\n- Support for `ImageData` directly from HTML Canvas, without type-casting or reboxing.\n\n  ```ts\n  import { compare } from '@4bitlabs/ssim';\n  \n  const current = ctx.getImageData(0, 0, width, height)  \n  const result = compare(source, current);\n  ```\n- `options` are now provided as an optional object, rather than positional arguments.\n\n  ```ts\n  compare(source, current, { luminance: false, windowSize: 16 })\n  ```\n\n- Added options to support to use `float64` precision, instead of `float32`.\n\n  ```ts\n  compare(source, current, { precision: 'f64' })\n  ```\n\n- Dropped `channels` support, only supports 4-channel RGBA-formatted bytes. If you need this, use the [reference implementation][refimpl].\n- Dropped `bitsPerComponent` support, only supports 8-bit components. If you need this, use the [reference implementation][refimpl].\n\n## Performance\n\nThe performance of `compare()` is ~2x better than the reference implementation for most use-cases. Mostly \nfrom avoiding `Float32Array` allocations and garbage collection inside hot-loops. Some of the function/callback \nmechanisms has been flattened—sacrificing some readability—to also reduce function overhead.\n\n```ts\n ✓ src/image-ssim.bench.ts 12028ms\n     name             hz     min     max    mean     p75     p99    p995    p999     rme  samples\n   · baseline     538.35  1.6835  6.0620  1.8575  1.9394  2.5029  2.7712  5.3191  ±0.49%     2692\n   · optimized  1,072.57  0.9002  1.9459  0.9323  0.9306  1.2270  1.2750  1.4360  ±0.19%     5363\n\n BENCH  Summary\n\n  optimized - src/image-ssim.bench.ts\n    1.99x faster than baseline\n```\n\nRun `npm run bench` to measure for yourself.\n\n## Comparing multiple candiates to a single source\n\nIf you are comparing multiple candidate `ImageData` against _one_ source `ImageData`, you can use `compareWith()`. \nThis amortizes the cost of analysis of the source image, for _faster_ comparisons against multiple candidate images.\n\n```ts\nimport { compareWith } from '@4bitlabs/ssim';\n\nconst compareWithSource = compareWith(sourceImage);\n\nconst r1 = compareWithSource(candidate1);\nconst r2 = compareWithSource(candidate2);\n\n// faster than:\n// const r1 = compare(sourceImage, candidate1);\n// const r2 = compare(sourceImage, candidate2);\n\nconsole.log(result1.ssim > result2.ssim ? 'Candidate 1 is closer' : 'Candidate 2 is closer')\n```\n\nThis is ~1.5x faster than `compare()` directly, and ~3x faster than the reference implementation.\n\n## License\n\nThis package is licensed under the MIT license; the same license as the original library. Source copyright notices have\nbeen left intact. See the [reference implementation][refimpl] for licensing details.\n\n[refimpl]: https://github.com/darosh/image-ssim-js","readmeFilename":"README.md"}