canvas-editor-engine 1.1.11 → 1.1.13
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.
|
@@ -13,18 +13,18 @@ class CropService {
|
|
|
13
13
|
return;
|
|
14
14
|
const filter = new filter_1.Filter(ctx);
|
|
15
15
|
const options = CropService.options;
|
|
16
|
-
const imageData = filter.
|
|
17
|
-
const
|
|
18
|
-
x: (config_1.default.CANVAS_SIZE.width / 2) - (
|
|
19
|
-
y: (config_1.default.CANVAS_SIZE.height / 2) - (
|
|
16
|
+
const { imageData, size } = filter.copyExtendedModel(options);
|
|
17
|
+
const position = {
|
|
18
|
+
x: (config_1.default.CANVAS_SIZE.width / 2) - (size.width / 2),
|
|
19
|
+
y: (config_1.default.CANVAS_SIZE.height / 2) - (size.height / 2),
|
|
20
20
|
};
|
|
21
|
-
filter.update(imageData,
|
|
21
|
+
filter.update(imageData, position);
|
|
22
22
|
store_1.default.store.imageState.reduce({
|
|
23
23
|
tempImageData: imageData,
|
|
24
|
-
position:
|
|
24
|
+
position: position,
|
|
25
25
|
size: {
|
|
26
|
-
width:
|
|
27
|
-
height:
|
|
26
|
+
width: size.width,
|
|
27
|
+
height: size.height,
|
|
28
28
|
}
|
|
29
29
|
}, "Use crop");
|
|
30
30
|
}
|
package/dist/types/image.d.ts
CHANGED
package/dist/types/image.js
CHANGED
package/dist/utils/filter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type IImageOptions, type IImageSize, type TBuff, type TRGBABuff } from "../types/image";
|
|
1
|
+
import { IExtendedImageDataModel, type IImageOptions, type IImageSize, type TBuff, type TRGBABuff } from "../types/image";
|
|
2
2
|
import type { ISize } from '../types/general';
|
|
3
3
|
export declare class Filter {
|
|
4
4
|
ctx: CanvasRenderingContext2D;
|
|
@@ -6,8 +6,9 @@ export declare class Filter {
|
|
|
6
6
|
constructor(ctx: CanvasRenderingContext2D);
|
|
7
7
|
setImageSize(size: IImageSize): void;
|
|
8
8
|
copy(options: IImageOptions): ImageData;
|
|
9
|
+
copyExtendedModel(options: IImageOptions): IExtendedImageDataModel;
|
|
9
10
|
update(imgData: ImageData, options: IImageOptions): void;
|
|
10
|
-
clearEmptyPixels(imageData: ImageData):
|
|
11
|
+
clearEmptyPixels(imageData: ImageData): IExtendedImageDataModel;
|
|
11
12
|
getSizeOfSparseMatrix(RGBAMatrix: TBuff<number[]>, tempSize: ISize): ISize;
|
|
12
13
|
getBuffCollection(imageData: ImageData): {
|
|
13
14
|
rowRGBABuff: TRGBABuff;
|
package/dist/utils/filter.js
CHANGED
|
@@ -17,8 +17,14 @@ class Filter {
|
|
|
17
17
|
const width = (options?.width) ? options.width : config_1.default.CANVAS_SIZE.width;
|
|
18
18
|
const height = (options?.height) ? options.height : config_1.default.CANVAS_SIZE.height;
|
|
19
19
|
const imgData = this.ctx.getImageData(options.x, options.y, width, height);
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
return imgData;
|
|
21
|
+
}
|
|
22
|
+
copyExtendedModel(options) {
|
|
23
|
+
const width = (options?.width) ? options.width : config_1.default.CANVAS_SIZE.width;
|
|
24
|
+
const height = (options?.height) ? options.height : config_1.default.CANVAS_SIZE.height;
|
|
25
|
+
const imgData = this.ctx.getImageData(options.x, options.y, width, height);
|
|
26
|
+
const extendedImageData = this.clearEmptyPixels(imgData);
|
|
27
|
+
return extendedImageData;
|
|
22
28
|
}
|
|
23
29
|
update(imgData, options) {
|
|
24
30
|
this.ctx.clearRect(0, 0, config_1.default.CANVAS_SIZE.width, config_1.default.CANVAS_SIZE.height);
|
|
@@ -42,7 +48,10 @@ class Filter {
|
|
|
42
48
|
const tempImageData = tempCtx.createImageData(tempSize.width, tempSize.height);
|
|
43
49
|
clearedBuff.forEach((_, i) => tempImageData.data[i] = clearedBuff[i]);
|
|
44
50
|
console.log('cleared', cleared);
|
|
45
|
-
return
|
|
51
|
+
return {
|
|
52
|
+
imageData: tempImageData,
|
|
53
|
+
size: tempSize
|
|
54
|
+
};
|
|
46
55
|
}
|
|
47
56
|
getSizeOfSparseMatrix(RGBAMatrix, tempSize) {
|
|
48
57
|
// case 1: Xcanvas -> Ximage && case 3: Ycanvas -> Yimage
|
|
@@ -83,11 +92,11 @@ class Filter {
|
|
|
83
92
|
console.log('case 4: Yimage <- Ycanvas; downIndex:', downIndex);
|
|
84
93
|
const reduceWidth = (tempWidth) => tempWidth - (leftIndex + rightIndex);
|
|
85
94
|
const reduceHeight = (tempHeight) => tempHeight - (upIndex + downIndex);
|
|
86
|
-
const
|
|
95
|
+
const resultSize = {
|
|
87
96
|
width: reduceWidth(tempSize.width),
|
|
88
97
|
height: reduceHeight(tempSize.height),
|
|
89
98
|
};
|
|
90
|
-
return
|
|
99
|
+
return resultSize;
|
|
91
100
|
}
|
|
92
101
|
getBuffCollection(imageData) {
|
|
93
102
|
const rowRGBABuff = this.getRowRGBABuff(imageData);
|