Skip to content

Commit e650436

Browse files
authored
Add contrast, brightnedd, saturation, gamma to/from Json (#495)
1 parent aa038fd commit e650436

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

__TESTS__/unit/fromJson/adjust.fromJson.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ describe('adjust.fromJson', () => {
55
const transformation = fromJson([
66
{ actionType: 'improve', mode: 'outdoor', blend: 30},
77
{ actionType: 'unsharpMask', strength: 50},
8-
{ actionType: 'saturation', level: 40}
8+
{ actionType: 'saturation', level: 40},
9+
{actionType: 'contrast', level: 40},
10+
{actionType: 'brightness', level: 30},
11+
{actionType: 'gamma', level: 30}
912
]);
1013

1114
expect(transformation.toString()).toStrictEqual([
1215
'e_improve:outdoor:30',
1316
'e_unsharp_mask:50',
14-
'e_saturation:40'
17+
'e_saturation:40',
18+
'e_contrast:40',
19+
'e_brightness:30',
20+
'e_gamma:30'
1521
].join('/'));
1622
});
1723
});

__TESTS__/unit/toJson/adjust.toJson.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,37 @@ describe('Adjust toJson()', () => {
3535
}
3636
]);
3737
});
38+
39+
it('adjust.contrast', () => {
40+
const transformation = new Transformation()
41+
.addAction(Adjust.contrast().level(50));
42+
expect(transformation.toJson()).toStrictEqual( [
43+
{
44+
actionType: 'contrast',
45+
level: 50
46+
}
47+
]);
48+
});
49+
50+
it('adjust.brightness', () => {
51+
const transformation = new Transformation()
52+
.addAction(Adjust.brightness().level(40));
53+
expect(transformation.toJson()).toStrictEqual( [
54+
{
55+
actionType: 'brightness',
56+
level: 40
57+
}
58+
]);
59+
});
60+
61+
it('adjust.gamma', () => {
62+
const transformation = new Transformation()
63+
.addAction(Adjust.gamma().level(40));
64+
expect(transformation.toJson()).toStrictEqual( [
65+
{
66+
actionType: 'gamma',
67+
level: 40
68+
}
69+
]);
70+
});
3871
});

src/internal/fromJson.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ const ActionModelMap: Record<string, IHasFromJson> = {
8787
improve: ImproveAction,
8888
unsharpMask: EffectActionWithStrength,
8989
saturation: EffectActionWithLevel,
90-
dpr: DeliveryDPRAction
90+
dpr: DeliveryDPRAction,
91+
contrast: EffectActionWithLevel,
92+
brightness: EffectActionWithLevel,
93+
gamma: EffectActionWithLevel
9194
};
9295

9396
/**

0 commit comments

Comments
 (0)