Skip to content

Commit cedae0b

Browse files
committed
add dither tojson
1 parent df4d86f commit cedae0b

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

__TESTS__/unit/toJson/effect.toJson.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Transformation} from "../../../src";
22
import {Effect} from "../../../src/actions/effect";
3+
import {halftone4x4Orthogonal} from "../../../src/qualifiers/dither";
34

45

56
describe('Effect toJson()', () => {
@@ -194,4 +195,15 @@ describe('Effect toJson()', () => {
194195
}
195196
]);
196197
});
198+
199+
it('effect.dither', () => {
200+
const transformation = new Transformation()
201+
.addAction(Effect.dither().type(halftone4x4Orthogonal()));
202+
expect(transformation.toJson()).toStrictEqual( [
203+
{
204+
actionType: 'Dither',
205+
type: 9,
206+
}
207+
]);
208+
});
197209
});

src/actions/effect/Dither.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {LeveledEffectAction} from "./EffectActions/LeveledEffectAction.js";
2+
import {IDitherModel} from "../../internal/models/IEffectActionModel.js";
23

34
/**
45
* @description Applies an ordered dither filter to the image.
@@ -7,13 +8,17 @@ import {LeveledEffectAction} from "./EffectActions/LeveledEffectAction.js";
78
* @see Visit {@link Actions.Effect|Effect} for an example
89
*/
910
class DitherEffectAction extends LeveledEffectAction {
11+
protected _actionModel: IDitherModel = {actionType: 'Dither'};
1012
/**
1113
*
1214
* @param {Qualifiers.Dither} ditherType - The dither type applied to the image
1315
* @return {this}
1416
*/
1517
type(ditherType:number): this {
16-
return this.setLevel(ditherType);
18+
this._actionModel.type = ditherType;
19+
const qualifierEffect = this.createEffectQualifier(this.effectType, ditherType);
20+
this.addQualifier(qualifierEffect);
21+
return this;
1722
}
1823
}
1924

src/internal/models/IEffectActionModel.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,16 @@ interface IMakeTransparentEffectModel extends IActionModel{
3737
tolerance?: number;
3838
color?: string;
3939
}
40-
export {IEffectActionWithLevelModel, ISimpleEffectActionModel, IShadowEffectActionModel, IColorizeModel, ICartoonifyEffectModel, IEffectOutlineModel, IMakeTransparentEffectModel};
40+
interface IDitherModel extends IActionModel {
41+
type?: number;
42+
}
43+
export {
44+
IEffectActionWithLevelModel,
45+
ISimpleEffectActionModel,
46+
IShadowEffectActionModel,
47+
IColorizeModel,
48+
ICartoonifyEffectModel,
49+
IEffectOutlineModel,
50+
IMakeTransparentEffectModel,
51+
IDitherModel
52+
};

0 commit comments

Comments
 (0)