Skip to content

Commit 7c9c7d5

Browse files
committed
add vectorize fromJson
1 parent bf0aa87 commit 7c9c7d5

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

__TESTS__/unit/fromJson/effect.fromJson.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ describe('effect.fromJson', () => {
2222
{ actionType: 'makeTransparent', tolerance: 5, color: 'red' },
2323
{ actionType: 'noise', level: 50 },
2424
{ actionType: 'vignette', level: 5 },
25-
{ actionType: 'dither', type: 9 }
25+
{ actionType: 'dither', type: 9 },
26+
{ actionType: 'vectorize', numOfColors: 17, detailLevel: 100 }
2627

2728
]);
2829

@@ -46,7 +47,8 @@ describe('effect.fromJson', () => {
4647
'co_red,e_makeTransparent:5',
4748
'e_noise:50',
4849
'e_vignette:5',
49-
'e_dither:9'
50+
'e_dither:9',
51+
'e_vectorize:colors:17:detail:100'
5052
].join('/'));
5153
});
5254
});

src/actions/effect/Vectorize.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Action} from "../../internal/Action.js";
22
import {Qualifier} from "../../internal/qualifier/Qualifier.js";
33
import {QualifierValue} from "../../internal/qualifier/QualifierValue.js";
44
import {IVectorizeEffectModel} from "../../internal/models/IEffectActionModel.js";
5+
import {IActionModel} from "../../internal/models/IActionModel.js";
56

67
/**
78
* @description Vectorizes the image.
@@ -100,6 +101,22 @@ class VectorizeEffectAction extends Action {
100101

101102
this.addQualifier(new Qualifier('e', str));
102103
}
104+
105+
static fromJson(actionModel: IActionModel): VectorizeEffectAction {
106+
const {actionType, paths, cornersLevel, despeckleLevel, detailLevel, numOfColors} = (actionModel as IVectorizeEffectModel);
107+
108+
// We are using this() to allow inheriting classes to use super.fromJson.apply(this, [actionModel])
109+
// This allows the inheriting classes to determine the class to be created
110+
const result = new this();
111+
paths && result.paths(paths);
112+
cornersLevel && result.cornersLevel(cornersLevel);
113+
despeckleLevel && result.despeckleLevel(despeckleLevel);
114+
detailLevel && result.detailsLevel(detailLevel);
115+
numOfColors && result.numOfColors(numOfColors);
116+
117+
return result;
118+
}
119+
103120
}
104121

105122

src/internal/fromJson.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {AccelerationEffectAction} from "../actions/effect/leveled/Accelerate.js"
3131
import {LoopEffectAction} from "../actions/effect/leveled/Loop.js";
3232
import {MakeTransparentEffectAction} from "../actions/effect/leveled/MakeTransparent.js";
3333
import {DitherEffectAction} from "../actions/effect/Dither.js";
34+
import {VectorizeEffectAction} from "../actions/effect/Vectorize.js";
3435

3536
const ActionModelMap: Record<string, IHasFromJson> = {
3637
scale: ResizeScaleAction,
@@ -67,7 +68,8 @@ const ActionModelMap: Record<string, IHasFromJson> = {
6768
makeTransparent: MakeTransparentEffectAction,
6869
noise: EffectActionWithLevel,
6970
vignette: EffectActionWithStrength,
70-
dither: DitherEffectAction
71+
dither: DitherEffectAction,
72+
vectorize: VectorizeEffectAction
7173

7274
};
7375

0 commit comments

Comments
 (0)