transform-image-data
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -1,31 +0,27 @@ | ||
type ImageArray = Uint8Array | Uint8ClampedArray; | ||
declare class TransformImageData { | ||
/** Input Data */ | ||
inData: ImageArray; | ||
/** Output Data */ | ||
outData: ImageArray; | ||
/** Width of input data */ | ||
import { TransferToWindow } from 'transfer-to-window'; | ||
interface param { | ||
/** 输入数据 */ | ||
inData: ArrayBuffer; | ||
/** 输入宽 */ | ||
inw: number; | ||
/** Height of input data */ | ||
/** 输入高 */ | ||
inh: number; | ||
/** Width of output data */ | ||
/** 输出数据 */ | ||
outData: ArrayBuffer; | ||
/** 输出宽 */ | ||
outw: number; | ||
/** Height of output data */ | ||
/** 输出高 */ | ||
outh: number; | ||
/** 输入窗口转化到输出窗口后最小的宽高尺寸;默认值:1 */ | ||
minWH?: number; | ||
/** 输入窗口转化到输出窗口后最大的宽高尺寸;默认值:Infinity */ | ||
maxWH?: number; | ||
} | ||
declare class TransformImageData extends TransferToWindow { | ||
/** 输入数据 */ | ||
inData: Uint32Array; | ||
/** 输出数据 */ | ||
outData: Uint32Array; | ||
constructor(param: param); | ||
/** | ||
* The transformation matrix from inData to outData. | ||
* [scale, 0, 0, 0, scale, 0, dx, dy, 1] | ||
*/ | ||
scale: number; | ||
dx: number; | ||
dy: number; | ||
/** | ||
* The transformation matrix from outData to inData. | ||
* [invScale, 0, 0, 0, invScale, 0, invDx, invDy, 1] | ||
*/ | ||
invScale: number; | ||
invDx: number; | ||
invDy: number; | ||
constructor(inData: ImageArray, inw: number, inh: number, outData: ImageArray, outw: number, outh: number); | ||
/** | ||
* Update outputData | ||
@@ -35,29 +31,25 @@ */ | ||
/** | ||
* Translate on outdata | ||
* 平移 | ||
* @param dx | ||
* @param dy | ||
* @param silent Whether update outData | ||
* @param silent 是否更新outData | ||
*/ | ||
translate(dx: number, dy: number, silent?: boolean): void; | ||
/** | ||
* Scale ratio multiple at position(cx,cy) on outdata | ||
* 以(cx,cy)为中心缩放ratio比例 | ||
* @param cx | ||
* @param cy | ||
* @param ratio | ||
* @param silent Whether update outData | ||
* @param silent 是否更新outData | ||
*/ | ||
zoom(cx: number, cy: number, ratio: number, silent?: boolean): void; | ||
/** | ||
* like: | ||
* 将输入数据完整放置于输出窗口的正中间;效果类似于CSS效果: | ||
* background-size: contain; | ||
* background-repeat: no-repeat; | ||
* background-position: center; | ||
* @param silent Whether update outData | ||
* @param silent 是否更新outData | ||
*/ | ||
resize(silent?: boolean): void; | ||
/** | ||
* Update the transformation matrix. | ||
*/ | ||
updateInvMatrix(): void; | ||
} | ||
export { TransformImageData, }; | ||
export { TransformImageData }; |
@@ -1,111 +0,68 @@ | ||
(function (factory) { | ||
if (typeof module === "object" && typeof module.exports === "object") { | ||
var v = factory(require, exports); | ||
if (v !== undefined) module.exports = v; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TransformImageData = void 0; | ||
const transfer_to_window_1 = require("transfer-to-window"); | ||
class TransformImageData extends transfer_to_window_1.TransferToWindow { | ||
constructor(param) { | ||
super(param, true); | ||
this.inData = new Uint32Array(param.inData); | ||
this.outData = new Uint32Array(param.outData); | ||
this.resize(); | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TransformImageData = void 0; | ||
class TransformImageData { | ||
constructor(inData, inw, inh, outData, outw, outh) { | ||
this.inData = inData; | ||
this.outData = outData; | ||
this.inw = inw; | ||
this.inh = inh; | ||
this.outw = outw; | ||
this.outh = outh; | ||
this.resize(true); | ||
} | ||
/** | ||
* Update outputData | ||
*/ | ||
update() { | ||
const { inw, inh, inData, outw, outh, outData, invScale, invDx, invDy } = this; | ||
for (let i = 0; i < outh; i++) { | ||
const r = Math.round(i * invScale + invDy); | ||
if (r < 0 || r >= inh) { | ||
for (let j = 0; j < outw; j++) { | ||
let index = (i * outw + j) * 4; | ||
outData[index + 3] = 0; | ||
} | ||
/** | ||
* Update outputData | ||
*/ | ||
update() { | ||
const { inw, inh, inData, outw, outh, outData, invScale, invDx, invDy } = this; | ||
for (let i = 0; i < outh; i++) { | ||
const r = Math.round(i * invScale + invDy); | ||
if (r < 0 || r >= inh) { | ||
outData.fill(0, i * outw, (i + 1) * outw); | ||
continue; | ||
} | ||
for (let j = 0; j < outw; j++) { | ||
const c = Math.round(j * invScale + invDx); | ||
let index = i * outw + j; | ||
if (c < 0 || c >= inw) { | ||
outData[index] = 0; | ||
continue; | ||
} | ||
for (let j = 0; j < outw; j++) { | ||
const c = Math.round(j * invScale + invDx); | ||
let index = (i * outw + j) * 4; | ||
if (c < 0 || c >= inw) { | ||
outData[index + 3] = 0; | ||
continue; | ||
} | ||
let ti = (r * inw + c) * 4; | ||
outData[index] = inData[ti]; | ||
outData[index + 1] = inData[ti + 1]; | ||
outData[index + 2] = inData[ti + 2]; | ||
outData[index + 3] = inData[ti + 3]; | ||
} | ||
let ti = r * inw + c; | ||
outData[index] = inData[ti]; | ||
} | ||
} | ||
/** | ||
* Translate on outdata | ||
* @param dx | ||
* @param dy | ||
* @param silent Whether update outData | ||
*/ | ||
translate(dx, dy, silent) { | ||
this.dx += dx; | ||
this.dy += dy; | ||
this.updateInvMatrix(); | ||
silent || this.update(); | ||
} | ||
/** | ||
* Scale ratio multiple at position(cx,cy) on outdata | ||
* @param cx | ||
* @param cy | ||
* @param ratio | ||
* @param silent Whether update outData | ||
*/ | ||
zoom(cx, cy, ratio, silent) { | ||
const { dx, dy, scale } = this; | ||
this.dx = (dx - cx) * ratio + cx; | ||
this.dy = (dy - cy) * ratio + cy; | ||
this.scale = scale * ratio; | ||
this.updateInvMatrix(); | ||
silent || this.update(); | ||
} | ||
/** | ||
* like: | ||
* background-size: contain; | ||
* background-repeat: no-repeat; | ||
* background-position: center; | ||
* @param silent Whether update outData | ||
*/ | ||
resize(silent) { | ||
const { inw, inh, outw, outh } = this; | ||
let scale; | ||
if (outw / outh > inw / inh) { | ||
scale = outh / inh; | ||
} | ||
else { | ||
scale = outw / inw; | ||
} | ||
this.scale = scale; | ||
this.dx = (outw - inw * scale) / 2; | ||
this.dy = (outh - inh * scale) / 2; | ||
this.updateInvMatrix(); | ||
silent || this.update(); | ||
} | ||
/** | ||
* Update the transformation matrix. | ||
*/ | ||
updateInvMatrix() { | ||
this.invScale = 1 / this.scale; | ||
this.invDx = -this.dx / this.scale; | ||
this.invDy = -this.dy / this.scale; | ||
} | ||
} | ||
exports.TransformImageData = TransformImageData; | ||
}); | ||
/** | ||
* 平移 | ||
* @param dx | ||
* @param dy | ||
* @param silent 是否更新outData | ||
*/ | ||
translate(dx, dy, silent) { | ||
super.translate(dx, dy); | ||
silent || this.update(); | ||
} | ||
/** | ||
* 以(cx,cy)为中心缩放ratio比例 | ||
* @param cx | ||
* @param cy | ||
* @param ratio | ||
* @param silent 是否更新outData | ||
*/ | ||
zoom(cx, cy, ratio, silent) { | ||
super.zoom(cx, cy, ratio); | ||
silent || this.update(); | ||
} | ||
/** | ||
* 将输入数据完整放置于输出窗口的正中间;效果类似于CSS效果: | ||
* background-size: contain; | ||
* background-repeat: no-repeat; | ||
* background-position: center; | ||
* @param silent 是否更新outData | ||
*/ | ||
resize(silent) { | ||
super.resize(); | ||
silent || this.update(); | ||
} | ||
} | ||
exports.TransformImageData = TransformImageData; |
{ | ||
"name": "transform-image-data", | ||
"version": "1.0.0", | ||
"description": "transform-image-data", | ||
"version": "2.0.0", | ||
"description": "将指定窗口大小的数据转化输出到另一窗口", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
@@ -20,3 +20,8 @@ "build": "tsc", | ||
}, | ||
"files": ["dist"] | ||
"files": [ | ||
"dist" | ||
], | ||
"dependencies": { | ||
"transfer-to-window": "^1.0.0" | ||
} | ||
} |
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
4101
1
122
+ Addedtransfer-to-window@^1.0.0
+ Addedtransfer-to-window@1.0.2(transitive)