From a244a18edd1404c921ff018a1d0fc966423a6ce7 Mon Sep 17 00:00:00 2001 From: JrMasterModelBuilder Date: Sun, 24 Sep 2023 15:41:06 -0400 Subject: [PATCH] Replaced upng-js with pngjs --- package-lock.json | 40 +++++++++++++++++++--------------------- package.json | 4 ++-- src/icon.ts | 44 ++++++++++++++++++++------------------------ 3 files changed, 41 insertions(+), 47 deletions(-) diff --git a/package-lock.json b/package-lock.json index 50a0996..a4c934b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.1.3", "license": "MPL-2.0", "dependencies": { - "upng-js": "^2.1.0" + "pngjs": "^7.0.0" }, "bin": { "shockpkg-icon-encoder": "bin/icon-encoder.js" @@ -20,7 +20,7 @@ "@babel/preset-env": "^7.22.20", "@babel/preset-typescript": "^7.22.15", "@types/node": "^20.6.4", - "@types/upng-js": "^2.1.3", + "@types/pngjs": "^6.0.2", "@typescript-eslint/eslint-plugin": "^6.7.2", "@typescript-eslint/parser": "^6.7.2", "babel-plugin-esm-resolver": "^2.3.1", @@ -2074,18 +2074,21 @@ "integrity": "sha512-nU6d9MPY0NBUMiE/nXd2IIoC4OLvsLpwAjheoAeuzgvDZA1Cb10QYg+91AF6zQiKWRN5i1m07x6sMe0niBznoQ==", "dev": true }, + "node_modules/@types/pngjs": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@types/pngjs/-/pngjs-6.0.2.tgz", + "integrity": "sha512-GO2/2guBQrrb4g+93j55VR30xaMCgmSXa/ifPbHS5MgheDRJy5x12fFB61Hn0juCo+VBFhYMFkJd6CBt8HRx4w==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/semver": { "version": "7.5.2", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.2.tgz", "integrity": "sha512-7aqorHYgdNO4DM36stTiGO3DvKoex9TQRwsJU6vMaFGyqpBA1MNZkz+PG3gaNUPpTAOYhT1WR7M1JyA3fbS9Cw==", "dev": true }, - "node_modules/@types/upng-js": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/@types/upng-js/-/upng-js-2.1.3.tgz", - "integrity": "sha512-ZVKlDixESlfpfqKN97BMT5+7R0uQhY9JyYLe0V1BedyOHusFkT1JdrVs7WN6L1t6n11rFYLQ31jcfTH6y1ppfg==", - "dev": true - }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "6.7.2", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.2.tgz", @@ -4679,11 +4682,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/pako": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", - "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" - }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -4790,6 +4788,14 @@ "node": ">=6" } }, + "node_modules/pngjs": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/pngjs/-/pngjs-7.0.0.tgz", + "integrity": "sha512-LKWqWJRhstyYo9pGvgor/ivk2w94eSjE3RGVuzLGlr3NmD8bf7RcYGze1mNdEHRP6TRP6rMuDHk5t44hnTRyow==", + "engines": { + "node": ">=14.19.0" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -5649,14 +5655,6 @@ "browserslist": ">= 4.21.0" } }, - "node_modules/upng-js": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/upng-js/-/upng-js-2.1.0.tgz", - "integrity": "sha512-d3xzZzpMP64YkjP5pr8gNyvBt7dLk/uGI67EctzDuVp4lCZyVMo0aJO6l/VDlgbInJYDY6cnClLoBp29eKWI6g==", - "dependencies": { - "pako": "^1.0.5" - } - }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/package.json b/package.json index 3539047..f5d91d1 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "copyright": "Copyright (c) 2019-2023 JrMasterModelBuilder", "license": "MPL-2.0", "dependencies": { - "upng-js": "^2.1.0" + "pngjs": "^7.0.0" }, "devDependencies": { "@babel/cli": "^7.22.15", @@ -62,7 +62,7 @@ "@babel/preset-env": "^7.22.20", "@babel/preset-typescript": "^7.22.15", "@types/node": "^20.6.4", - "@types/upng-js": "^2.1.3", + "@types/pngjs": "^6.0.2", "@typescript-eslint/eslint-plugin": "^6.7.2", "@typescript-eslint/parser": "^6.7.2", "babel-plugin-esm-resolver": "^2.3.1", diff --git a/src/icon.ts b/src/icon.ts index 989a907..2bdb586 100644 --- a/src/icon.ts +++ b/src/icon.ts @@ -1,4 +1,4 @@ -import UPNG from 'upng-js'; +import {PNG} from 'pngjs'; import {IImageData} from './types'; @@ -18,11 +18,17 @@ export abstract class Icon { * @returns Image data. */ protected _decodePngToRgba(data: Readonly) { - const image = UPNG.decode(data); + const { + width, + height, + data: d + } = PNG.sync.read( + Buffer.from(data.buffer, data.byteOffset, data.byteLength) + ); return { - width: image.width, - height: image.height, - data: new Uint8Array(UPNG.toRGBA8(image)[0]) + width, + height, + data: new Uint8Array(d.buffer, d.byteOffset, d.byteLength) } as IImageData; } @@ -33,25 +39,15 @@ export abstract class Icon { * @returns PNG data. */ protected _encodeRgbaToPng(imageData: Readonly) { - return new Uint8Array( - ( - UPNG.encode as ( - imgs: ArrayBuffer[], - w: number, - h: number, - cnum: number, - dels?: number[], - forbidPlte?: boolean - ) => ArrayBuffer - )( - [imageData.data.buffer], - imageData.width, - imageData.height, - 0, - [], - true - ) - ); + const {width, height, data} = imageData; + const png = new PNG({width, height}); + png.data = Buffer.from(data.buffer, data.byteOffset, data.byteLength); + const d = PNG.sync.write(png, { + deflateLevel: 9, + deflateStrategy: 1, + deflateChunkSize: 32 * 1024 + }); + return new Uint8Array(d.buffer, d.byteOffset, d.byteLength); } /**