skinview-utils
Advanced tools
Comparing version 0.5.8 to 0.5.9
@@ -126,2 +126,17 @@ function copyImage(context, sX, sY, w, h, dX, dY, flipHorizontal) { | ||
} | ||
function isAreaBlack(context, x0, y0, w, h) { | ||
const imgData = context.getImageData(x0, y0, w, h); | ||
for (let x = 0; x < w; x++) { | ||
for (let y = 0; y < h; y++) { | ||
const offset = (x + y * w) * 4; | ||
if (!(imgData.data[offset + 0] === 0 && | ||
imgData.data[offset + 1] === 0 && | ||
imgData.data[offset + 2] === 0 && | ||
imgData.data[offset + 3] === 0xff)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
export function inferModelType(canvas) { | ||
@@ -166,11 +181,17 @@ // The right arm area of *default* skins: | ||
// as transparent pixels are not allowed in the first layer. | ||
// If the 4 areas are all black, the skin is also considered as slim. | ||
const scale = computeSkinScale(canvas.width); | ||
const context = canvas.getContext("2d"); | ||
const checkArea = (x, y, w, h) => hasTransparency(context, x * scale, y * scale, w * scale, h * scale); | ||
const isSlim = checkArea(50, 16, 2, 4) || | ||
checkArea(54, 20, 2, 12) || | ||
checkArea(42, 48, 2, 4) || | ||
checkArea(46, 52, 2, 12); | ||
const checkTransparency = (x, y, w, h) => hasTransparency(context, x * scale, y * scale, w * scale, h * scale); | ||
const checkBlack = (x, y, w, h) => isAreaBlack(context, x * scale, y * scale, w * scale, h * scale); | ||
const isSlim = (checkTransparency(50, 16, 2, 4) || | ||
checkTransparency(54, 20, 2, 12) || | ||
checkTransparency(42, 48, 2, 4) || | ||
checkTransparency(46, 52, 2, 12)) || | ||
(checkBlack(50, 16, 2, 4) && | ||
checkBlack(54, 20, 2, 12) && | ||
checkBlack(42, 48, 2, 4) && | ||
checkBlack(46, 52, 2, 12)); | ||
return isSlim ? "slim" : "default"; | ||
} | ||
//# sourceMappingURL=process.js.map |
{ | ||
"name": "skinview-utils", | ||
"version": "0.5.8", | ||
"version": "0.5.9", | ||
"description": "Utilities for working with Minecraft skins", | ||
@@ -14,3 +14,3 @@ "type": "module", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^15.0.0", | ||
"@rollup/plugin-commonjs": "^15.1.0", | ||
"@rollup/plugin-image": "^2.0.5", | ||
@@ -21,15 +21,15 @@ "@rollup/plugin-node-resolve": "^9.0.0", | ||
"@types/mocha": "^8.0.3", | ||
"@typescript-eslint/eslint-plugin": "^4.1.0", | ||
"@typescript-eslint/parser": "^4.1.0", | ||
"@typescript-eslint/eslint-plugin": "^4.3.0", | ||
"@typescript-eslint/parser": "^4.3.0", | ||
"chai": "^4.2.0", | ||
"eslint": "^7.7.0", | ||
"karma": "^5.1.1", | ||
"eslint": "^7.10.0", | ||
"karma": "^5.2.3", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-mocha": "^2.0.1", | ||
"karma-rollup-preprocessor": "^7.0.5", | ||
"mocha": "^8.1.1", | ||
"puppeteer": "^5.2.1", | ||
"mocha": "^8.1.3", | ||
"puppeteer": "^5.3.1", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.26.3", | ||
"typescript": "^4.0.2" | ||
"rollup": "^2.28.2", | ||
"typescript": "^4.0.3" | ||
}, | ||
@@ -36,0 +36,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27923
300