-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
185 lines (146 loc) · 4.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
'use strict'
const { UnknownOperationError } = require('./errors')
module.exports = require('bindings')('darkroom-xmp-tools')
const tools = module.exports
const MaskType = {
NONE: 0,
CIRCLE: 1,
PATH: 2,
GROUP: 4,
CLONE: 8,
GRADIENT: 16,
ELLIPSE: 32,
BRUSH: 64,
NON_CLONE: 128
}
const EllipseFlags = {
EQUIDISTANT: 0,
PROPORTIONAL: 1
}
const ExposureMode = {
EXPOSURE_MODE_MANUAL: 'EXPOSURE_MODE_MANUAL',
EXPOSURE_MODE_DEFLICKER: 'EXPOSURE_MODE_DEFLICKER'
}
const LevelsMode = {
LEVELS_MODE_MANUAL: 'LEVELS_MODE_MANUAL',
LEVELS_MODE_AUTOMATIC: 'LEVELS_MODE_AUTOMATIC'
}
const GaussianOrder = {
GAUSSIAN_ZERO: 'DT_IOP_GAUSSIAN_ZERO',
GAUSSIAN_ONE: 'DT_IOP_GAUSSIAN_ONE',
GAUSSIAN_TOW: 'DT_IOP_GAUSSIAN_TWO'
}
const BasecurveType = {
CUBIC_SPLINE: 0,
CATMULL_ROM: 1,
MONOTONE_HERMITE: 2
}
const ShadHiAlgo = {
SHADHI_ALGO_GAUSSIAN: 'SHADHI_ALGO_GAUSSIAN',
SHADHI_ALGO_BILATERAL: 'SHADHI_ALGO_BILATERAL'
}
const DefringeMode = {
MODE_GLOBAL_AVERAGE: 'MODE_GLOBAL_AVERAGE',
MODE_LOCAL_AVERAGE: 'MODE_LOCAL_AVERAGE',
MODE_STATIC: 'MODE_STATIC'
}
const ImageOrientation = {
ORIENTATION_NULL: 'ORIENTATION_NULL',
ORIENTATION_NONE: 'ORIENTATION_NONE',
ORIENTATION_FLIP_Y: 'ORIENTATION_FLIP_Y',
ORIENTATION_FLIP_X: 'ORIENTATION_FLIP_X',
ORIENTATION_SWAP_XY: 'ORIENTATION_SWAP_XY',
ORIENTATION_ROTATE_180_DEG: 'ORIENTATION_ROTATE_180_DEG',
ORIENTATION_ROTATE_CCW_90_DEG: 'ORIENTATION_ROTATE_CCW_90_DEG',
ORIENTATION_ROTATE_CW_90_DEG: 'ORIENTATION_ROTATE_CW_90_DEG',
ORIENTATION_421: 'ORIENTATION_421'
}
// Circle mask
function decodeCircleMask (encodedMask) {
return tools.decodeMaskPoints(MaskType.CIRCLE, 1, encodedMask)[0]
}
function encodeCircleMask (mask) {
return tools.encodeMaskPoints(MaskType.CIRCLE, [mask])
}
// Ellipse mask
function decodeEllipseMask (encodedMask) {
return tools.decodeMaskPoints(MaskType.ELLIPSE, 1, encodedMask)[0]
}
function encodeEllipseMask (mask) {
return tools.encodeMaskPoints(MaskType.ELLIPSE, [mask])
}
// Gradient mask
function decodeGradientMask (encodedMask) {
return tools.decodeMaskPoints(MaskType.GRADIENT, 1, encodedMask)[0]
}
function encodeGradientMask (mask) {
return tools.encodeMaskPoints(MaskType.GRADIENT, [mask])
}
function decodeParams (operation, paramsStr) {
switch (operation) {
case 'sharpen':
return tools.decodeSharpenParams(paramsStr)
case 'levels':
return tools.decodeLevelsParams(paramsStr)
case 'shadhi':
return tools.decodeShadhiParams(paramsStr)
case 'exposure':
return tools.decodeExposureParams(paramsStr)
case 'blend':
return tools.decodeBlendParams(paramsStr)
case 'clipping':
return tools.decodeClippingParams(paramsStr)
case 'defringe':
return tools.decodeDefringeParams(paramsStr)
case 'flip':
return tools.decodeFlipParams(paramsStr)
case 'basecurve':
return tools.decodeBasecurveParams(paramsStr)
default:
throw new UnknownOperationError(operation)
}
}
function encodeParams (operation, params) {
switch (operation) {
case 'sharpen':
return tools.encodeSharpenParams(params)
case 'levels':
return tools.encodeLevelsParams(params)
case 'shadhi':
return tools.encodeShadhiParams(params)
case 'exposure':
return tools.encodeExposureParams(params)
case 'blend':
return tools.encodeBlendParams(params)
case 'clipping':
return tools.encodeClippingParams(params)
case 'defringe':
return tools.encodeDefringeParams(params)
case 'flip':
return tools.encodeFlipParams(params)
case 'basecurve':
return tools.encodeBasecurveParams(params)
default:
throw new UnknownOperationError(operation)
}
}
Object.assign(module.exports, {
MaskType,
EllipseFlags,
ExposureMode,
LevelsMode,
GaussianOrder,
BasecurveType,
ShadHiAlgo,
DefringeMode,
ImageOrientation,
decodeCircleMask,
encodeCircleMask,
decodeEllipseMask,
encodeEllipseMask,
decodeGradientMask,
encodeGradientMask,
decodeParams,
encodeParams,
UnknownOperationError
})