canvas-editor-engine 1.1.12 → 1.1.14
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/filters/collection/vague.d.ts +2 -2
- package/dist/filters/collection/vague.js +15 -3
- package/dist/services/crop.service.js +8 -8
- package/dist/services/draw.service.d.ts +1 -1
- package/dist/services/draw.service.js +12 -1
- package/dist/types/history.d.ts +9 -0
- package/dist/types/image.d.ts +11 -0
- package/dist/types/image.js +1 -0
- package/dist/utils/filter.d.ts +3 -2
- package/dist/utils/filter.js +14 -5
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { IFilterOptions, IImageOptions, TFilterMethod } from "../../types/image";
|
|
1
|
+
import type { IFilterOptions, IImageLoggingDataVague, IImageOptions, TFilterMethod } from "../../types/image";
|
|
2
2
|
import { Filter } from "../../utils/filter";
|
|
3
3
|
export default class VagueFilter extends Filter {
|
|
4
4
|
options: IImageOptions;
|
|
5
5
|
filterList: TFilterMethod[];
|
|
6
6
|
constructor(ctx: CanvasRenderingContext2D, options: IImageOptions);
|
|
7
|
-
on(action: TFilterMethod, filterOptions: IFilterOptions): Promise<
|
|
7
|
+
on(action: TFilterMethod, filterOptions: IFilterOptions): Promise<IImageLoggingDataVague>;
|
|
8
8
|
pixel(imageData: ImageData, filterOptions: IFilterOptions): ImageData;
|
|
9
9
|
private getQualityBuff;
|
|
10
10
|
private getMostCommonQuanlityBuff;
|
|
@@ -12,10 +12,22 @@ class VagueFilter extends filter_1.Filter {
|
|
|
12
12
|
}
|
|
13
13
|
on(action, filterOptions) {
|
|
14
14
|
return new Promise((resolve) => {
|
|
15
|
-
const
|
|
15
|
+
const options = this.options;
|
|
16
|
+
const imageData = this.copy(options);
|
|
16
17
|
const rowImageData = this[action](imageData, filterOptions);
|
|
17
|
-
this.update(rowImageData,
|
|
18
|
-
return resolve(
|
|
18
|
+
this.update(rowImageData, options);
|
|
19
|
+
return resolve({
|
|
20
|
+
imageData: rowImageData,
|
|
21
|
+
position: {
|
|
22
|
+
x: options.x,
|
|
23
|
+
y: options.y,
|
|
24
|
+
},
|
|
25
|
+
size: {
|
|
26
|
+
width: rowImageData.width,
|
|
27
|
+
height: rowImageData.height,
|
|
28
|
+
},
|
|
29
|
+
quality: filterOptions.quality,
|
|
30
|
+
});
|
|
19
31
|
});
|
|
20
32
|
}
|
|
21
33
|
pixel(imageData, filterOptions) {
|
|
@@ -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
|
}
|
|
@@ -11,5 +11,5 @@ export declare class SCImage {
|
|
|
11
11
|
constructor(src: string, ctx: CanvasRenderingContext2D);
|
|
12
12
|
get(): HTMLImageElement;
|
|
13
13
|
draw(options: IDrawImageArgs): Promise<unknown>;
|
|
14
|
-
vague(options: IImageOptions, filterOptions: IFilterOptions): Promise<
|
|
14
|
+
vague(options: IImageOptions, filterOptions: IFilterOptions): Promise<import("../types/image").IImageLoggingDataVague>;
|
|
15
15
|
}
|
|
@@ -27,7 +27,18 @@ class DrawService {
|
|
|
27
27
|
static drawSmoothImage(useStore, options, filterOptions) {
|
|
28
28
|
const filterArgs = DrawService.getFilterArgs(useStore, options);
|
|
29
29
|
event_service_1.default.dispatch('loading-start');
|
|
30
|
-
this.scImage.vague(filterArgs, filterOptions)
|
|
30
|
+
this.scImage.vague(filterArgs, filterOptions)
|
|
31
|
+
.then(({ imageData, position, size, quality }) => {
|
|
32
|
+
store_1.default.store.imageState.reduce({
|
|
33
|
+
tempImageData: imageData,
|
|
34
|
+
position: position,
|
|
35
|
+
size: {
|
|
36
|
+
width: size.width,
|
|
37
|
+
height: size.height,
|
|
38
|
+
}
|
|
39
|
+
}, `[Filter Vague] quality: ${quality}`);
|
|
40
|
+
})
|
|
41
|
+
.finally(() => {
|
|
31
42
|
event_service_1.default.dispatch('loading-end');
|
|
32
43
|
});
|
|
33
44
|
}
|
package/dist/types/history.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { IPosition, ISize } from "./general";
|
|
1
2
|
export interface IHistoryLine {
|
|
2
3
|
stateName: string;
|
|
3
4
|
stateValue: any;
|
|
4
5
|
view: string;
|
|
5
6
|
}
|
|
6
7
|
export type TReducerNames = 'SET_HISTORY' | 'UPDATE_HISTORY' | 'UNDO' | 'REDO';
|
|
8
|
+
export interface IImageLoggingData {
|
|
9
|
+
imageData: ImageData;
|
|
10
|
+
size: ISize;
|
|
11
|
+
position: IPosition;
|
|
12
|
+
}
|
|
13
|
+
export interface IImageLoggingDataVague extends IImageLoggingData {
|
|
14
|
+
quality: number;
|
|
15
|
+
}
|
package/dist/types/image.d.ts
CHANGED
|
@@ -31,3 +31,14 @@ export declare const enum E_RGBA {
|
|
|
31
31
|
b = 2,
|
|
32
32
|
a = 3
|
|
33
33
|
}
|
|
34
|
+
export interface IExtendedImageDataModel {
|
|
35
|
+
imageData: ImageData;
|
|
36
|
+
size: ISize;
|
|
37
|
+
}
|
|
38
|
+
export interface IImageLoggingData {
|
|
39
|
+
imageData: ImageData;
|
|
40
|
+
size: ISize;
|
|
41
|
+
position: IPosition;
|
|
42
|
+
}
|
|
43
|
+
export interface IImageLoggingDataVague extends IImageLoggingData, IFilterOptions {
|
|
44
|
+
}
|
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);
|