canvas-editor-engine 1.1.9 → 1.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/image.d.ts +6 -0
- package/dist/types/image.js +1 -0
- package/dist/utils/filter.d.ts +3 -1
- package/dist/utils/filter.js +24 -13
- package/package.json +1 -1
package/dist/types/image.d.ts
CHANGED
package/dist/types/image.js
CHANGED
package/dist/utils/filter.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type IImageOptions, type IImageSize, type TBuff, type TRGBABuff } from "../types/image";
|
|
2
|
+
import type { ISize } from '../types/general';
|
|
2
3
|
export declare class Filter {
|
|
3
4
|
ctx: CanvasRenderingContext2D;
|
|
4
5
|
imageSize: IImageSize;
|
|
@@ -7,6 +8,7 @@ export declare class Filter {
|
|
|
7
8
|
copy(options: IImageOptions): ImageData;
|
|
8
9
|
update(imgData: ImageData, options: IImageOptions): void;
|
|
9
10
|
clearEmptyPixels(imageData: ImageData): void;
|
|
11
|
+
getSizeOfSparseMatrix(RGBAMatrix: TBuff<number[]>, tempSize: ISize): ISize;
|
|
10
12
|
getBuffCollection(imageData: ImageData): {
|
|
11
13
|
rowRGBABuff: TRGBABuff;
|
|
12
14
|
hexBuff: `#${string}`[];
|
package/dist/utils/filter.js
CHANGED
|
@@ -27,11 +27,26 @@ class Filter {
|
|
|
27
27
|
clearEmptyPixels(imageData) {
|
|
28
28
|
const rowRGBABuff = this.getRowRGBABuff(imageData);
|
|
29
29
|
const RGBAMatrix = this.getRGBAMatrix(rowRGBABuff, { width: imageData.width, height: imageData.height });
|
|
30
|
-
const
|
|
30
|
+
const beforeSize = {
|
|
31
31
|
width: imageData.width,
|
|
32
32
|
height: imageData.height,
|
|
33
33
|
};
|
|
34
|
-
;
|
|
34
|
+
const tempSize = this.getSizeOfSparseMatrix(RGBAMatrix, beforeSize);
|
|
35
|
+
console.log('beforeSize', beforeSize);
|
|
36
|
+
console.log('tempSize', tempSize);
|
|
37
|
+
// const cleared = rowRGBABuff.filter((byteArray) => {
|
|
38
|
+
// const alpha = byteArray[E_RGBA.a];
|
|
39
|
+
// return !!alpha;
|
|
40
|
+
// });
|
|
41
|
+
// const clearedBuff = cleared.flat();
|
|
42
|
+
// const tempCanvas = document.createElement('canvas');
|
|
43
|
+
// const tempCtx = tempCanvas.getContext('2d');
|
|
44
|
+
// const tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
|
|
45
|
+
// clearedBuff.forEach((_, i) => tempImageData.data[i] = clearedBuff[i]);
|
|
46
|
+
// console.log('cleared', cleared);
|
|
47
|
+
// return tempImageData;
|
|
48
|
+
}
|
|
49
|
+
getSizeOfSparseMatrix(RGBAMatrix, tempSize) {
|
|
35
50
|
// case 1: Xcanvas -> Ximage && case 3: Ycanvas -> Yimage
|
|
36
51
|
let leftIndex;
|
|
37
52
|
let upIndex;
|
|
@@ -68,17 +83,13 @@ class Filter {
|
|
|
68
83
|
}
|
|
69
84
|
console.log('case 2: Ximage <- Xcanvas; rightIndex:', rightIndex);
|
|
70
85
|
console.log('case 4: Yimage <- Ycanvas; downIndex:', downIndex);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
// const tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
|
|
79
|
-
// clearedBuff.forEach((_, i) => tempImageData.data[i] = clearedBuff[i]);
|
|
80
|
-
// console.log('cleared', cleared);
|
|
81
|
-
// return tempImageData;
|
|
86
|
+
const reduceWidth = (tempWidth) => tempWidth - (leftIndex + rightIndex);
|
|
87
|
+
const reduceHeight = (tempHeight) => tempHeight - (upIndex + downIndex);
|
|
88
|
+
const result = {
|
|
89
|
+
width: reduceWidth(tempSize.width),
|
|
90
|
+
height: reduceHeight(tempSize.height),
|
|
91
|
+
};
|
|
92
|
+
return result;
|
|
82
93
|
}
|
|
83
94
|
getBuffCollection(imageData) {
|
|
84
95
|
const rowRGBABuff = this.getRowRGBABuff(imageData);
|