canvas-editor-engine 1.1.6 → 1.1.7
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 +1 -1
- package/dist/utils/filter.d.ts +4 -4
- package/dist/utils/filter.js +55 -7
- package/package.json +1 -1
package/dist/types/image.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface IImageSize extends ISize {
|
|
|
18
18
|
}
|
|
19
19
|
export type TRGBABuff = TByteRGBColor[];
|
|
20
20
|
export type TByteRGBColor = [number, number, number, number];
|
|
21
|
-
export type TBuff =
|
|
21
|
+
export type TBuff<T> = T[][];
|
|
22
22
|
export type TQualityBuff = TStringMatrix;
|
|
23
23
|
export type TRangeCommit = IPixelPosition[][];
|
|
24
24
|
export type TFilterMethod = 'pixel';
|
package/dist/utils/filter.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { IImageOptions, IImageSize, TRGBABuff } from "../types/image";
|
|
2
|
-
import type { TStringMatrix } from '../types/general';
|
|
1
|
+
import type { IImageOptions, IImageSize, TBuff, TRGBABuff } from "../types/image";
|
|
3
2
|
export declare class Filter {
|
|
4
3
|
ctx: CanvasRenderingContext2D;
|
|
5
4
|
imageSize: IImageSize;
|
|
@@ -7,12 +6,13 @@ export declare class Filter {
|
|
|
7
6
|
setImageSize(size: IImageSize): void;
|
|
8
7
|
copy(options: IImageOptions): ImageData;
|
|
9
8
|
update(imgData: ImageData, options: IImageOptions): void;
|
|
10
|
-
clearEmptyPixels(imageData: ImageData):
|
|
9
|
+
clearEmptyPixels(imageData: ImageData): void;
|
|
11
10
|
getBuffCollection(imageData: ImageData): {
|
|
12
11
|
rowRGBABuff: TRGBABuff;
|
|
13
12
|
hexBuff: `#${string}`[];
|
|
14
|
-
buff:
|
|
13
|
+
buff: TBuff<string>;
|
|
15
14
|
};
|
|
16
15
|
private getBuff;
|
|
16
|
+
private getRGBAMatrix;
|
|
17
17
|
private getRowRGBABuff;
|
|
18
18
|
}
|
package/dist/utils/filter.js
CHANGED
|
@@ -26,13 +26,44 @@ class Filter {
|
|
|
26
26
|
}
|
|
27
27
|
clearEmptyPixels(imageData) {
|
|
28
28
|
const rowRGBABuff = this.getRowRGBABuff(imageData);
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
const RGBAMatrix = this.getRGBAMatrix(rowRGBABuff, { width: imageData.width, height: imageData.height });
|
|
30
|
+
const tempSize = {
|
|
31
|
+
width: imageData.width,
|
|
32
|
+
height: imageData.height,
|
|
33
|
+
};
|
|
34
|
+
;
|
|
35
|
+
// case 1: Xcanvas -> Ximage
|
|
36
|
+
let leftIndex;
|
|
37
|
+
for (const [iy, row] of RGBAMatrix.entries()) {
|
|
38
|
+
for (const [ix, rowItem] of row.entries()) {
|
|
39
|
+
const isNotEmpty = rowItem[3 /* E_RGBA.a */] !== 0;
|
|
40
|
+
if (isNotEmpty) {
|
|
41
|
+
leftIndex = ix;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (leftIndex !== undefined) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
console.log('case 1: Xcanvas -> Ximage; leftIndex:', leftIndex);
|
|
50
|
+
// case 2: Ximage <- Xcanvas
|
|
51
|
+
let rightIndex;
|
|
52
|
+
// case 3: Ycanvas -> Yimage
|
|
53
|
+
let upIndex;
|
|
54
|
+
// case 4: Yimage <- Ycanvas
|
|
55
|
+
let downIndex;
|
|
56
|
+
// const cleared = rowRGBABuff.filter((byteArray) => {
|
|
57
|
+
// const alpha = byteArray[E_RGBA.a];
|
|
58
|
+
// return !!alpha;
|
|
59
|
+
// });
|
|
60
|
+
// const clearedBuff = cleared.flat();
|
|
61
|
+
// const tempCanvas = document.createElement('canvas');
|
|
62
|
+
// const tempCtx = tempCanvas.getContext('2d');
|
|
63
|
+
// const tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
|
|
64
|
+
// clearedBuff.forEach((_, i) => tempImageData.data[i] = clearedBuff[i]);
|
|
65
|
+
// console.log('cleared', cleared);
|
|
66
|
+
// return tempImageData;
|
|
36
67
|
}
|
|
37
68
|
getBuffCollection(imageData) {
|
|
38
69
|
const rowRGBABuff = this.getRowRGBABuff(imageData);
|
|
@@ -53,6 +84,23 @@ class Filter {
|
|
|
53
84
|
});
|
|
54
85
|
return buff;
|
|
55
86
|
}
|
|
87
|
+
getRGBAMatrix(RGBABuff, size) {
|
|
88
|
+
const maybeSize = {
|
|
89
|
+
width: size.width || this.imageSize.width,
|
|
90
|
+
height: size.height || this.imageSize.height,
|
|
91
|
+
};
|
|
92
|
+
const distanceRow = (0, lodash_1.range)(0, maybeSize.height).map((i) => maybeSize.width * i);
|
|
93
|
+
const buff = [];
|
|
94
|
+
let indexOfDistance = 0;
|
|
95
|
+
RGBABuff.forEach((pxRGBA, pxIndex) => {
|
|
96
|
+
if (pxIndex >= distanceRow[indexOfDistance + 1]) {
|
|
97
|
+
indexOfDistance++;
|
|
98
|
+
}
|
|
99
|
+
buff[indexOfDistance] ??= [];
|
|
100
|
+
buff[indexOfDistance].push(pxRGBA);
|
|
101
|
+
});
|
|
102
|
+
return buff;
|
|
103
|
+
}
|
|
56
104
|
getRowRGBABuff(imageData) {
|
|
57
105
|
const rowRGBABuff = []; // [ [0, 0, 0, 0], [0, 0, 0, 0], ... ]
|
|
58
106
|
let colorIndx = 0;
|