Skip to content

Commit 0eaae47

Browse files
committed
gracefully accept/ignore unknown brush inputs
closes #128 (cherry picked from commit 24dfe53)
1 parent f4fd974 commit 0eaae47

File tree

3 files changed

+225
-0
lines changed

3 files changed

+225
-0
lines changed

mypaint-brush.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,12 @@ update_brush_setting_from_json_object(MyPaintBrush *self,
12791279
return FALSE;
12801280
}
12811281

1282+
if (!(input_id >= 0 && input_id < MYPAINT_BRUSH_INPUTS_COUNT)) {
1283+
fprintf(stderr, "Warning: Unknown input_id: %d for input: %s\n",
1284+
input_id, input_name);
1285+
return FALSE;
1286+
}
1287+
12821288
const int number_of_mapping_points = json_object_array_length(input_obj);
12831289

12841290
mypaint_brush_set_mapping_n(self, setting_id, input_id, number_of_mapping_points);
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
{
2+
"comment": "MyPaint brush file",
3+
"group": "",
4+
"parent_brush_name": "",
5+
"settings": {
6+
"anti_aliasing": {
7+
"base_value": 0.0,
8+
"inputs": {}
9+
},
10+
"change_color_h": {
11+
"base_value": 0.0,
12+
"inputs": {}
13+
},
14+
"change_color_hsl_s": {
15+
"base_value": 0.0,
16+
"inputs": {}
17+
},
18+
"change_color_hsv_s": {
19+
"base_value": 0.0,
20+
"inputs": {}
21+
},
22+
"change_color_l": {
23+
"base_value": 0.0,
24+
"inputs": {}
25+
},
26+
"change_color_v": {
27+
"base_value": 0.0,
28+
"inputs": {}
29+
},
30+
"color_h": {
31+
"base_value": 0.6354166666666666,
32+
"inputs": {}
33+
},
34+
"color_s": {
35+
"base_value": 0.8807339449541285,
36+
"inputs": {}
37+
},
38+
"color_v": {
39+
"base_value": 0.42745098039215684,
40+
"inputs": {}
41+
},
42+
"colorize": {
43+
"base_value": 0.0,
44+
"inputs": {}
45+
},
46+
"custom_input": {
47+
"base_value": 0.0,
48+
"inputs": {}
49+
},
50+
"custom_input_slowness": {
51+
"base_value": 0.0,
52+
"inputs": {}
53+
},
54+
"dabs_per_actual_radius": {
55+
"base_value": 5.0,
56+
"inputs": {}
57+
},
58+
"dabs_per_basic_radius": {
59+
"base_value": 0.0,
60+
"inputs": {}
61+
},
62+
"dabs_per_second": {
63+
"base_value": 0.0,
64+
"inputs": {}
65+
},
66+
"direction_filter": {
67+
"base_value": 2.0,
68+
"inputs": {}
69+
},
70+
"elliptical_dab_angle": {
71+
"base_value": 90.0,
72+
"inputs": {}
73+
},
74+
"elliptical_dab_ratio": {
75+
"base_value": 1.0,
76+
"inputs": {}
77+
},
78+
"eraser": {
79+
"base_value": 0.0,
80+
"inputs": {}
81+
},
82+
"hardness": {
83+
"base_value": 0.2,
84+
"inputs": {}
85+
},
86+
"lock_alpha": {
87+
"base_value": 0.0,
88+
"inputs": {}
89+
},
90+
"offset_by_random": {
91+
"base_value": 1.6,
92+
"inputs": {
93+
"pressurebad": [
94+
[
95+
0,
96+
0
97+
],
98+
[
99+
1.0,
100+
-1.4
101+
]
102+
]
103+
}
104+
},
105+
"offset_by_speed": {
106+
"base_value": 0.0,
107+
"inputs": {}
108+
},
109+
"offset_by_speed_slowness": {
110+
"base_value": 1.0,
111+
"inputs": {}
112+
},
113+
"opaque": {
114+
"base_value": 0.4,
115+
"inputs": {
116+
"pressure": [
117+
[
118+
0,
119+
0
120+
],
121+
[
122+
1.0,
123+
0.4
124+
]
125+
]
126+
}
127+
},
128+
"opaque_linearize": {
129+
"base_value": 0.0,
130+
"inputs": {}
131+
},
132+
"opaque_multiply": {
133+
"base_value": 0.0,
134+
"inputs": {
135+
"pressure": [
136+
[
137+
0,
138+
0
139+
],
140+
[
141+
1.0,
142+
1.0
143+
]
144+
]
145+
}
146+
},
147+
"radius_by_random": {
148+
"base_value": 0.0,
149+
"inputs": {}
150+
},
151+
"radius_logarithmic": {
152+
"base_value": 0.7,
153+
"inputs": {}
154+
},
155+
"restore_color": {
156+
"base_value": 0.0,
157+
"inputs": {}
158+
},
159+
"slow_tracking": {
160+
"base_value": 2.0,
161+
"inputs": {}
162+
},
163+
"slow_tracking_per_dab": {
164+
"base_value": 0.0,
165+
"inputs": {}
166+
},
167+
"smudge": {
168+
"base_value": 0.0,
169+
"inputs": {}
170+
},
171+
"smudge_length": {
172+
"base_value": 0.5,
173+
"inputs": {}
174+
},
175+
"smudge_radius_log": {
176+
"base_value": 0.0,
177+
"inputs": {}
178+
},
179+
"speed1_gamma": {
180+
"base_value": 4.0,
181+
"inputs": {}
182+
},
183+
"speed1_slowness": {
184+
"base_value": 0.04,
185+
"inputs": {}
186+
},
187+
"speed2_gamma": {
188+
"base_value": 4.0,
189+
"inputs": {}
190+
},
191+
"speed2_slowness": {
192+
"base_value": 0.8,
193+
"inputs": {}
194+
},
195+
"stroke_duration_logarithmic": {
196+
"base_value": 4.0,
197+
"inputs": {}
198+
},
199+
"stroke_holdtime": {
200+
"base_value": 0.0,
201+
"inputs": {}
202+
},
203+
"stroke_threshold": {
204+
"base_value": 0.0,
205+
"inputs": {}
206+
},
207+
"tracking_noise": {
208+
"base_value": 0.0,
209+
"inputs": {}
210+
}
211+
},
212+
"version": 3
213+
}

tests/test-brush-load.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ main(int argc, char **argv)
4444
LIBMYPAINT_TESTING_ABS_TOP_SRCDIR
4545
"/tests/brushes/bad/some_unknown_settings.myb"
4646
},
47+
{
48+
"/brush/load/bad/some_unknown_inputs",
49+
test_brush_load_succeeds,
50+
LIBMYPAINT_TESTING_ABS_TOP_SRCDIR
51+
"/tests/brushes/bad/some_unknown_inputs.myb"
52+
},
4753

4854
// Irrecoverably pathological brush data, missing global stuff
4955
// or entirely useless. We expect these to fail.

0 commit comments

Comments
 (0)