MCPcopy Create free account
hub / github.com/microsoft/SandDance / prepareGrids

Function prepareGrids

docs/app/js/sanddance-app.js:105780–105801  ·  view source on GitHub ↗
(imgData, width, height, glyphWidth, glyphHeight, gridOuter, gridInner)

Source from the content-addressed store, hash-verified

105778 this.middle = Math.round(size / 2 * (navigator.userAgent.indexOf("Gecko/") >= 0 ? 1.2 : 1));
105779}
105780function prepareGrids(imgData, width, height, glyphWidth, glyphHeight, gridOuter, gridInner) {
105781 // Initialize grids outside the glyph range to alpha 0
105782 gridOuter.fill(INF, 0, width * height);
105783 gridInner.fill(0, 0, width * height);
105784 var offset = (width - glyphWidth) / 2; // This is zero if we're not extracting metrics
105785 for(var y = 0; y < glyphHeight; y++)for(var x = 0; x < glyphWidth; x++){
105786 var j = (y + offset) * width + x + offset;
105787 var a = imgData.data[4 * (y * glyphWidth + x) + 3] / 255; // alpha value
105788 if (a === 1) {
105789 gridOuter[j] = 0;
105790 gridInner[j] = INF;
105791 } else if (a === 0) {
105792 gridOuter[j] = INF;
105793 gridInner[j] = 0;
105794 } else {
105795 var b = Math.max(0, 0.5 - a);
105796 var c = Math.max(0, a - 0.5);
105797 gridOuter[j] = b * b;
105798 gridInner[j] = c * c;
105799 }
105800 }
105801}
105802function extractAlpha(alphaChannel, width, height, gridOuter, gridInner, radius, cutoff) {
105803 for(var i = 0; i < width * height; i++){
105804 var d = Math.sqrt(gridOuter[i]) - Math.sqrt(gridInner[i]);

Callers 1

sanddance-app.jsFile · 0.70

Calls 1

maxMethod · 0.45

Tested by

no test coverage detected