Skip to content

Commit a05d255

Browse files
committed
parametric LUTs: added support for "choice" parameters with a custom order of options
1 parent ee57b57 commit a05d255

4 files changed

Lines changed: 127 additions & 98 deletions

File tree

rtengine/clutparams.cc

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,41 @@ bool CLUTParamDescriptor::fill_from_json(cJSON *root)
222222
if (sz >= 3 && sz <= 7) {
223223
n = cJSON_GetArrayItem(root, 2);
224224
if (cJSON_IsArray(n)) {
225-
for (int i = 0, k = cJSON_GetArraySize(n); i < k; ++i) {
225+
int k = cJSON_GetArraySize(n);
226+
bool all_strings = true;
227+
for (int i = 0; i < k; ++i) {
226228
auto v = cJSON_GetArrayItem(n, i);
227229
if (!cJSON_IsString(v)) {
230+
if (all_strings && i > 0) {
231+
return false;
232+
}
233+
all_strings = false;
234+
if (!(cJSON_IsArray(v) && cJSON_GetArraySize(v) == 2 &&
235+
cJSON_IsString(cJSON_GetArrayItem(v, 0)) &&
236+
cJSON_IsNumber(cJSON_GetArrayItem(v, 1)))) {
237+
return false;
238+
}
239+
} else if (!all_strings) {
228240
return false;
229241
}
230-
choices.push_back(cJSON_GetStringValue(v));
242+
}
243+
if (all_strings) {
244+
for (int i = 0; i < k; ++i) {
245+
auto v = cJSON_GetArrayItem(n, i);
246+
choices.push_back(std::make_pair(cJSON_GetStringValue(v), i));
247+
}
248+
} else {
249+
std::vector<bool> seen(k);
250+
for (int i = 0; i < k; ++i) {
251+
auto v = cJSON_GetArrayItem(n, i);
252+
int idx = int(cJSON_GetArrayItem(v, 1)->valuedouble);
253+
Glib::ustring s = cJSON_GetStringValue(cJSON_GetArrayItem(v, 0));
254+
if (idx < 0 || idx >= k || seen[idx]) {
255+
return false;
256+
}
257+
seen[idx] = true;
258+
choices.push_back(std::make_pair(s, idx));
259+
}
231260
}
232261
type = CLUTParamType::PT_CHOICE;
233262
if (sz >= 4) {

rtengine/clutparams.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct CLUTParamDescriptor {
4444
double value_min;
4545
double value_max;
4646
std::vector<double> value_default;
47-
std::vector<Glib::ustring> choices;
47+
std::vector<std::pair<Glib::ustring, int>> choices;
4848
Glib::ustring gui_name;
4949
Glib::ustring gui_group;
5050
double gui_step;

rtgui/clutparamspanel.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ void CLUTParamsPanel::setParams(const rtengine::CLUTParamDescriptorList &params)
181181
} break;
182182
case rtengine::CLUTParamType::PT_CHOICE: {
183183
MyComboBoxText *c = Gtk::manage(new MyComboBoxText());
184-
for (auto l : d.choices) {
185-
c->append(lbl(l));
184+
for (auto &p : d.choices) {
185+
c->append(lbl(p.first));
186186
}
187187
Gtk::HBox *hb = Gtk::manage(new Gtk::HBox());
188188
hb->pack_start(*Gtk::manage(new Gtk::Label(lbl(d.gui_name) + ": ")),
@@ -296,7 +296,7 @@ rtengine::CLUTParamValueMap CLUTParamsPanel::getValue() const
296296
v[0] = static_cast<Gtk::CheckButton *>(w)->get_active();
297297
break;
298298
case rtengine::CLUTParamType::PT_CHOICE:
299-
v[0] = static_cast<MyComboBoxText *>(w)->get_active_row_number();
299+
v[0] = d.choices[static_cast<MyComboBoxText *>(w)->get_active_row_number()].second;
300300
break;
301301
case rtengine::CLUTParamType::PT_CURVE:
302302
case rtengine::CLUTParamType::PT_FLATCURVE:
@@ -335,7 +335,7 @@ void CLUTParamsPanel::setValue(const rtengine::CLUTParamValueMap &val)
335335
static_cast<Gtk::CheckButton *>(w)->set_active(bool(v));
336336
break;
337337
case rtengine::CLUTParamType::PT_CHOICE:
338-
static_cast<MyComboBoxText *>(w)->set_active(int(v));
338+
static_cast<MyComboBoxText *>(w)->set_active(d.choices[int(v)].second);
339339
break;
340340
case rtengine::CLUTParamType::PT_CURVE:
341341
case rtengine::CLUTParamType::PT_FLATCURVE:

tools/extlut/ART_spectral_film.json

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -22,102 +22,102 @@
2222
["wb", "WB", 2700, 16000, 6500, 1],
2323
["tint", "Tint", -1.0, 1.0, 0, 0.01],
2424
["film", "Film stock", [
25-
"AgfaVista100",
26-
"FujiC200",
27-
"FujiEterna500",
28-
"FujiEterna500Vivid",
29-
"FujiFP100C",
30-
"FujiInstaxColor",
31-
"FujiNatura1600",
32-
"FujiPro160C",
33-
"FujiPro160S",
34-
"FujiPro400H",
35-
"FujiProvia100F",
36-
"FujiSuperiaReala",
37-
"FujiSuperiaXtra400",
38-
"FujiVelvia50",
39-
"Kodachrome64",
40-
"Kodak5207",
41-
"Kodak5219",
42-
"Kodak5222Dev12",
43-
"Kodak5222Dev4",
44-
"Kodak5222Dev5",
45-
"Kodak5222Dev6",
46-
"Kodak5222Dev9",
47-
"Kodak5247",
48-
"Kodak5247II",
49-
"Kodak5248",
50-
"Kodak5250",
51-
"Kodak5277",
52-
"Kodak5293",
53-
"KodakAerochromeIII",
54-
"KodakAerocolor",
55-
"KodakAerocolorHigh",
56-
"KodakAerocolorLow",
57-
"KodakDyeTransferSeparation",
58-
"KodakEXR5248",
59-
"KodakEktachromeE100",
60-
"KodakEktar100",
61-
"KodakGold200",
62-
"KodakPortra160",
63-
"KodakPortra400",
64-
"KodakPortra800",
65-
"KodakPortra800At1600",
66-
"KodakPortra800At3200",
67-
"KodakTriX400Dev11",
68-
"KodakTriX400Dev6",
69-
"KodakTriX400Dev7",
70-
"KodakTriX400Dev9",
71-
"KodakUltramax400",
72-
"KodakVericolorIII",
73-
"TechnicolorIV",
74-
"TechnicolorIValt1",
75-
"TechnicolorIValt2",
76-
"Kodak5203",
77-
"Kodak5213"
25+
["AgfaVista100", 0],
26+
["FujiC200", 1],
27+
["FujiEterna500", 2],
28+
["FujiEterna500Vivid", 3],
29+
["FujiFP100C", 4],
30+
["FujiInstaxColor", 5],
31+
["FujiNatura1600", 6],
32+
["FujiPro160C", 7],
33+
["FujiPro160S", 8],
34+
["FujiPro400H", 9],
35+
["FujiProvia100F", 10],
36+
["FujiSuperiaReala", 11],
37+
["FujiSuperiaXtra400", 12],
38+
["FujiVelvia50", 13],
39+
["Kodachrome64", 14],
40+
["Kodak5203", 51],
41+
["Kodak5207", 15],
42+
["Kodak5213", 52],
43+
["Kodak5219", 16],
44+
["Kodak5222Dev12", 17],
45+
["Kodak5222Dev4", 18],
46+
["Kodak5222Dev5", 19],
47+
["Kodak5222Dev6", 20],
48+
["Kodak5222Dev9", 21],
49+
["Kodak5247", 22],
50+
["Kodak5247II", 23],
51+
["Kodak5248", 24],
52+
["Kodak5250", 25],
53+
["Kodak5277", 26],
54+
["Kodak5293", 27],
55+
["KodakAerochromeIII", 28],
56+
["KodakAerocolor", 29],
57+
["KodakAerocolorHigh", 30],
58+
["KodakAerocolorLow", 31],
59+
["KodakDyeTransferSeparation", 32],
60+
["KodakEXR5248", 33],
61+
["KodakEktachromeE100", 34],
62+
["KodakEktar100", 35],
63+
["KodakGold200", 36],
64+
["KodakPortra160", 37],
65+
["KodakPortra400", 38],
66+
["KodakPortra800", 39],
67+
["KodakPortra800At1600", 40],
68+
["KodakPortra800At3200", 41],
69+
["KodakTriX400Dev11", 42],
70+
["KodakTriX400Dev6", 43],
71+
["KodakTriX400Dev7", 44],
72+
["KodakTriX400Dev9", 45],
73+
["KodakUltramax400", 46],
74+
["KodakVericolorIII", 47],
75+
["TechnicolorIV", 48],
76+
["TechnicolorIValt1", 49],
77+
["TechnicolorIValt2", 50]
7878
], 0],
7979
["red_light", "Red printer light", -1, 1, 0, 0.01],
8080
["green_light", "Green printer light", -1, 1, 0, 0.01],
8181
["blue_light", "Blue printer light", -1, 1, 0, 0.01],
8282
["paper", "Print stock", [
83-
"Fuji3513DI",
84-
"FujiCrystalArchiveDPII",
85-
"FujiCrystalArchiveMaxima",
86-
"FujiCrystalArchiveSuperTypeC",
87-
"FujiflexNew",
88-
"FujiflexOld",
89-
"Kodak2303Dev2",
90-
"Kodak2303Dev3",
91-
"Kodak2303Dev5",
92-
"Kodak2303Dev7",
93-
"Kodak2303Dev9",
94-
"Kodak2383",
95-
"Kodak2393",
96-
"Kodak5381",
97-
"Kodak5383",
98-
"Kodak5384",
99-
"KodakDuraflexPlus",
100-
"KodakDyeTransferKodachrome",
101-
"KodakDyeTransferNegative",
102-
"KodakEnduraPremier",
103-
"KodakExr5386",
104-
"KodakPolymax",
105-
"KodakPolymaxGrade0",
106-
"KodakPolymaxGrade1",
107-
"KodakPolymaxGrade2",
108-
"KodakPolymaxGrade3",
109-
"KodakPolymaxGrade4",
110-
"KodakPolymaxGrade5",
111-
"KodakPolymaxGradeNeg1",
112-
"KodakPortraEndura",
113-
"KodakSupraEndura",
114-
"TechinicolorV",
115-
"None",
116-
"FujiCrystalArchiveProPDII",
117-
"IlfochromeMicrographicM",
118-
"IlfochromeMicrographicP",
119-
"KodakDyeTransferSlide",
120-
"KodakEktachromeRadianceIIIPaper"
83+
["Fuji3513DI", 0],
84+
["FujiCrystalArchiveDPII", 1],
85+
["FujiCrystalArchiveMaxima", 2],
86+
["FujiCrystalArchiveProPDII", 33],
87+
["FujiCrystalArchiveSuperTypeC", 3],
88+
["FujiflexNew", 4],
89+
["FujiflexOld", 5],
90+
["IlfochromeMicrographicM", 34],
91+
["IlfochromeMicrographicP", 35],
92+
["Kodak2303Dev2", 6],
93+
["Kodak2303Dev3", 7],
94+
["Kodak2303Dev5", 8],
95+
["Kodak2303Dev7", 9],
96+
["Kodak2303Dev9", 10],
97+
["Kodak2383", 11],
98+
["Kodak2393", 12],
99+
["Kodak5381", 13],
100+
["Kodak5383", 14],
101+
["Kodak5384", 15],
102+
["KodakDuraflexPlus", 16],
103+
["KodakDyeTransferKodachrome", 17],
104+
["KodakDyeTransferNegative", 18],
105+
["KodakDyeTransferSlide", 36],
106+
["KodakEktachromeRadianceIIIPaper", 37],
107+
["KodakEnduraPremier", 19],
108+
["KodakExr5386", 20],
109+
["KodakPolymax", 21],
110+
["KodakPolymaxGrade0", 22],
111+
["KodakPolymaxGrade1", 23],
112+
["KodakPolymaxGrade2", 24],
113+
["KodakPolymaxGrade3", 25],
114+
["KodakPolymaxGrade4", 26],
115+
["KodakPolymaxGrade5", 27],
116+
["KodakPolymaxGradeNeg1", 28],
117+
["KodakPortraEndura", 29],
118+
["KodakSupraEndura", 30],
119+
["TechinicolorV", 31],
120+
["None", 32]
121121
], 0],
122122
["projector_wb", "Projector wb", 2700, 16000, 6500, 1],
123123
["white_point", "White point", 0.5, 2.0, 1.0, 0.001],

0 commit comments

Comments
 (0)