{"_id":"bitmap-sdf","_rev":"2926683","name":"bitmap-sdf","description":"Calculate SDF for image/bw-data/array","dist-tags":{"latest":"1.0.4"},"maintainers":[{"name":"dfcreative","email":"df.creative@gmail.com"}],"time":{"modified":"2023-03-03T06:03:47.000Z","created":"2017-07-18T18:11:53.091Z","1.0.4":"2022-05-02T18:55:11.323Z","1.0.3":"2018-01-12T15:39:10.665Z","1.0.2":"2018-01-05T20:32:44.898Z","1.0.1":"2017-08-23T20:43:41.673Z","1.0.0":"2017-07-18T18:11:53.091Z"},"users":{},"author":{"name":"Dima Yv","email":"dfcreative@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/dfcreative/bitmap-sdf.git"},"versions":{"1.0.4":{"name":"bitmap-sdf","version":"1.0.4","description":"Calculate SDF for image/bw-data/array","main":"index.js","devDependencies":{"bubleify":"^0.7.0","enable-mobile":"^1.0.7"},"scripts":{"test":"budo test","build":"browserify test.js -g bubleify | indexhtmlify | metadataify | github-cornerify > index.html"},"repository":{"type":"git","url":"git+https://github.com/dfcreative/bitmap-sdf.git"},"keywords":["sdf","signed-distance","image-sdf","bitmap","bwdist","tiny-sdf"],"author":{"name":"Dima Yv","email":"dfcreative@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/dfcreative/bitmap-sdf/issues"},"homepage":"https://github.com/dfcreative/bitmap-sdf#readme","gitHead":"78de3569d32404a7009f62bea3befca55838118a","_id":"bitmap-sdf@1.0.4","_nodeVersion":"16.13.2","_npmVersion":"8.3.0","dist":{"shasum":"e87b8b1d84ee846567cfbb29d60eedd34bca5b6f","size":11535,"noattachment":false,"key":"/bitmap-sdf/-/bitmap-sdf-1.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/bitmap-sdf/download/bitmap-sdf-1.0.4.tgz"},"_npmUser":{"name":"dfcreative","email":"df.creative@gmail.com"},"directories":{},"maintainers":[{"name":"dfcreative","email":"df.creative@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bitmap-sdf_1.0.4_1651517711199_0.2646646063669398"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-05-02T19:00:15.862Z","publish_time":1651517711323,"_cnpm_publish_time":1651517711323},"1.0.3":{"name":"bitmap-sdf","version":"1.0.3","description":"Calculate SDF for image/bw-data/array","main":"index.js","dependencies":{"clamp":"^1.0.1"},"devDependencies":{"enable-mobile":"^1.0.7","bubleify":"^0.7.0"},"scripts":{"test":"budo test","build":"browserify test.js -g bubleify | indexhtmlify | metadataify | github-cornerify > index.html"},"repository":{"type":"git","url":"git+https://github.com/dfcreative/bitmap-sdf.git"},"keywords":["sdf","signed-distance","image-sdf","bitmap","bwdist","tiny-sdf"],"author":{"name":"Dima Yv","email":"dfcreative@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/dfcreative/bitmap-sdf/issues"},"homepage":"https://github.com/dfcreative/bitmap-sdf#readme","gitHead":"0b8bb4f0a2bbc25bbc0d1bb1ce31d7d82765d718","_id":"bitmap-sdf@1.0.3","_npmVersion":"5.6.0","_nodeVersion":"8.1.2","_npmUser":{"name":"dfcreative","email":"df.creative@gmail.com"},"dist":{"shasum":"c99913e5729357a6fd350de34158180c013880b2","size":11609,"noattachment":false,"key":"/bitmap-sdf/-/bitmap-sdf-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/bitmap-sdf/download/bitmap-sdf-1.0.3.tgz"},"maintainers":[{"name":"dfcreative","email":"df.creative@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bitmap-sdf-1.0.3.tgz_1515771549805_0.012204900616779923"},"directories":{},"publish_time":1515771550665,"_hasShrinkwrap":false,"_cnpm_publish_time":1515771550665,"_cnpmcore_publish_time":"2021-12-16T21:38:58.545Z"},"1.0.2":{"name":"bitmap-sdf","version":"1.0.2","description":"Calculate SDF for image/bw-data/array","main":"index.js","dependencies":{"clamp":"^1.0.1"},"devDependencies":{"enable-mobile":"^1.0.7","bubleify":"^0.7.0"},"scripts":{"test":"budo test","build":"browserify test.js -g bubleify | indexhtmlify | metadataify | github-cornerify > index.html"},"repository":{"type":"git","url":"git+https://github.com/dfcreative/bitmap-sdf.git"},"keywords":["sdf","signed-distance","image-sdf","bitmap","bwdist","tiny-sdf"],"author":{"name":"Dima Yv","email":"dfcreative@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/dfcreative/bitmap-sdf/issues"},"homepage":"https://github.com/dfcreative/bitmap-sdf#readme","gitHead":"3a5620a07e9ffbbaed18526af74c7544890a899e","_id":"bitmap-sdf@1.0.2","_npmVersion":"5.6.0","_nodeVersion":"8.1.2","_npmUser":{"name":"dfcreative","email":"df.creative@gmail.com"},"dist":{"shasum":"113b184e607c44b76f923fc2dea34e2d5d9895cc","size":11482,"noattachment":false,"key":"/bitmap-sdf/-/bitmap-sdf-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/bitmap-sdf/download/bitmap-sdf-1.0.2.tgz"},"maintainers":[{"name":"dfcreative","email":"df.creative@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bitmap-sdf-1.0.2.tgz_1515184364799_0.16221345053054392"},"directories":{},"publish_time":1515184364898,"_hasShrinkwrap":false,"_cnpm_publish_time":1515184364898,"_cnpmcore_publish_time":"2021-12-16T21:38:58.757Z"},"1.0.1":{"name":"bitmap-sdf","version":"1.0.1","description":"Calculate SDF for image/bw-data/array","main":"index.js","dependencies":{"clamp":"^1.0.1"},"devDependencies":{"enable-mobile":"^1.0.7","bubleify":"^0.7.0"},"scripts":{"test":"budo test","build":"browserify test.js -g bubleify | indexhtmlify | metadataify | github-cornerify > index.html"},"repository":{"type":"git","url":"git+https://github.com/dfcreative/bitmap-sdf.git"},"keywords":["sdf","signed-distance","image-sdf","bitmap","bwdist","tiny-sdf"],"author":{"name":"Dima Yv","email":"dfcreative@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/dfcreative/bitmap-sdf/issues"},"homepage":"https://github.com/dfcreative/bitmap-sdf#readme","gitHead":"d9ccc1d2a5954577c690c2c523e9c02e54f00c3a","_id":"bitmap-sdf@1.0.1","_shasum":"47743081413c1fee75b8727a553a74545b9daac8","_from":".","_npmVersion":"4.6.1","_nodeVersion":"8.1.2","_npmUser":{"name":"dfcreative","email":"df.creative@gmail.com"},"dist":{"shasum":"47743081413c1fee75b8727a553a74545b9daac8","size":11519,"noattachment":false,"key":"/bitmap-sdf/-/bitmap-sdf-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/bitmap-sdf/download/bitmap-sdf-1.0.1.tgz"},"maintainers":[{"name":"dfcreative","email":"df.creative@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bitmap-sdf-1.0.1.tgz_1503521020677_0.9237783153075725"},"directories":{},"publish_time":1503521021673,"_hasShrinkwrap":false,"_cnpm_publish_time":1503521021673,"_cnpmcore_publish_time":"2021-12-16T21:38:58.990Z"},"1.0.0":{"name":"bitmap-sdf","version":"1.0.0","description":"Calculate SDF for image/bw-data/array","main":"index.js","dependencies":{"clamp":"^1.0.1","enable-mobile":"^1.0.7"},"devDependencies":{"bubleify":"^0.7.0"},"scripts":{"test":"budo test","build":"browserify test.js -g bubleify | indexhtmlify | metadataify | github-cornerify > index.html"},"repository":{"type":"git","url":"git+https://github.com/dfcreative/bitmap-sdf.git"},"keywords":["sdf","signed-distance","image-sdf","bitmap","bwdist","tiny-sdf"],"author":{"name":"Dima Yv","email":"dfcreative@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/dfcreative/bitmap-sdf/issues"},"homepage":"https://github.com/dfcreative/bitmap-sdf#readme","gitHead":"5533216d6638c5351cd3c6df50ba19a433c7abc6","_id":"bitmap-sdf@1.0.0","_shasum":"23243ba42af8100060ad7c9826157a5daea458d2","_from":".","_npmVersion":"4.6.1","_nodeVersion":"8.1.2","_npmUser":{"name":"dfcreative","email":"df.creative@gmail.com"},"dist":{"shasum":"23243ba42af8100060ad7c9826157a5daea458d2","size":29399,"noattachment":false,"key":"/bitmap-sdf/-/bitmap-sdf-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/bitmap-sdf/download/bitmap-sdf-1.0.0.tgz"},"maintainers":[{"name":"dfcreative","email":"df.creative@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/bitmap-sdf-1.0.0.tgz_1500401511370_0.4757901984266937"},"directories":{},"publish_time":1500401513091,"_hasShrinkwrap":false,"_cnpm_publish_time":1500401513091,"_cnpmcore_publish_time":"2021-12-16T21:38:59.224Z"}},"readme":"# bitmap-sdf [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges)\r\n\r\nCalculate signed distance field for an image / bw-data. Fork of [tiny-sdf](https://github.com/mapbox/tiny-sdf) with reduced API.\r\n\r\n![bitmap-sdf](preview.png)\r\n\r\n[Demo](https://dy.github.io/bitmap-sdf/)\r\n\r\n## Usage\r\n\r\n[![npm install bitmap-sdf](https://nodei.co/npm/bitmap-sdf.png?mini=true)](https://npmjs.org/package/bitmap-sdf/)\r\n\r\n```js\r\nlet calcSdf = requrie('bitmap-sdf')\r\n\r\n//draw image\r\nlet canvas = document.body.appendChild(document.createElement('canvas'))\r\nlet w = canvas.width = 200, h = canvas.height = 200\r\nlet ctx = canvas.getContext('2d')\r\nctx.fillStyle = 'white'\r\nctx.font = 'bold 30px sans-serif'\r\nctx.fillText('X', 20, 20)\r\n\r\n//calculate distances\r\nlet distances = calcSdf(canvas)\r\n\r\n//show distances\r\nlet imgArr = new Uint8ClampedArray(w*h*4)\r\nfor (let i = 0; i < w; i++) {\r\n\tfor (let j = 0; j < h; j++) {\r\n\t\timgArr[j*w*4 + i*4 + 0] = arr[j*w+i]*255\r\n\t\timgArr[j*w*4 + i*4 + 1] = arr[j*w+i]*255\r\n\t\timgArr[j*w*4 + i*4 + 2] = arr[j*w+i]*255\r\n\t\timgArr[j*w*4 + i*4 + 3] = 255\r\n\t}\r\n}\r\nvar data = new ImageData(imgArr, w, h)\r\nctx.putImageData(data, 0, 0)\r\n```\r\n\r\n### dist = calcSdf(source, options?)\r\n\r\nCalculate distance field for the input `source` data, based on `options`. Returns 1-channel array with distance values from `0..1` range.\r\n\r\n#### Source:\r\n\r\nType | Meaning\r\n---|---\r\n_Canvas_, _Context2D_ | Calculates sdf for the full canvas image data based on `options.channel`, by default `0`, ie. red channel.\r\n_ImageData_ | Calculates sdf for the image data based on `options.channel`\r\n_Uint8ClampedArray_, _Uint8Array_ | Handles raw pixel data, requires `options.width` and `options.height`. Stride is detected from `width` and `height`.\r\n_Float32Array_, _Array_ | Handles raw numbers from `0..1` range, requires `options.width` and `options.height`. Stride is detected from `width` and `height`.\r\n\r\n#### Options:\r\n\r\nProperty | Default | Meaning\r\n---|---|---\r\n`cutoff` | `0.25` | Cutoff parameter, balance between SDF inside `1` and outside `0` of glyph\r\n`radius` | `10` | Max length of SDF, ie. the size of SDF around the `cutoff`\r\n`width` | `canvas.width` | Width of input data, if array\r\n`height` | `canvas.height` | Height of input data, if array\r\n`channel` | `0` | Channel number, `0` is red, `1` is green, `2` is blue, `3` is alpha.\r\n`stride` | `null` | Explicitly indicate number of channels per pixel. Not needed if `height` and `width` are provided.\r\n\r\n## See also\r\n\r\n* [font-atlas-sdf](https://github.com/hughsk/font-atlas-sdf) − generate sdf atlas for a font.\r\n* [tiny-sdf](https://github.com/mapbox/tiny-sdf) − fast glyph signed distance field generation.\r\n* [optical-properties](https://github.com/dfcreative/optical-properties) − glyph optical center and bounding box calculation\r\n\r\n## Alternatives\r\n\r\n* [disttransform.wat](https://github.com/LingDong-/wasm-fun/blob/master/wat/disttransform.wat)\r\n\r\n## License\r\n\r\n(c) 2017 Dima Yv. MIT License\r\n\r\nDevelopment supported by plot.ly.\r\n","_attachments":{},"homepage":"https://github.com/dfcreative/bitmap-sdf#readme","bugs":{"url":"https://github.com/dfcreative/bitmap-sdf/issues"},"license":"MIT"}