MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / load_cube_file

Method load_cube_file

src/effects/ColorMap.cpp:21–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19using namespace openshot;
20
21void ColorMap::load_cube_file()
22{
23 if (lut_path.empty()) {
24 lut_data.clear();
25 lut_size = 0;
26 lut_type = LUTType::None;
27 needs_refresh = false;
28 return;
29 }
30
31 int parsed_size = 0;
32 std::vector<float> parsed_data;
33 bool parsed_is_3d = false;
34 std::array<float, 3> parsed_domain_min{0.0f, 0.0f, 0.0f};
35 std::array<float, 3> parsed_domain_max{1.0f, 1.0f, 1.0f};
36
37 #pragma omp critical(load_lut)
38 {
39 QFile file(QString::fromStdString(lut_path));
40 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
41 // leave parsed_size == 0
42 } else {
43 QTextStream in(&file);
44 QRegularExpression ws_re("\\s+");
45 auto parse_domain_line = [&](const QString &line) {
46 if (!line.startsWith("DOMAIN_MIN") && !line.startsWith("DOMAIN_MAX"))
47 return;
48 auto parts = line.split(ws_re);
49 if (parts.size() < 4)
50 return;
51 auto assign_values = [&](std::array<float, 3> &target) {
52 target[0] = parts[1].toFloat();
53 target[1] = parts[2].toFloat();
54 target[2] = parts[3].toFloat();
55 };
56 if (line.startsWith("DOMAIN_MIN"))
57 assign_values(parsed_domain_min);
58 else
59 assign_values(parsed_domain_max);
60 };
61
62 auto try_parse = [&](const QString &keyword, bool want3d) -> bool {
63 if (!file.seek(0) || !in.seek(0))
64 return false;
65
66 QString line;
67 int detected_size = 0;
68 while (!in.atEnd()) {
69 line = in.readLine().trimmed();
70 parse_domain_line(line);
71 if (line.startsWith(keyword)) {
72 auto parts = line.split(ws_re);
73 if (parts.size() >= 2) {
74 detected_size = parts[1].toInt();
75 }
76 break;
77 }
78 }

Callers

nothing calls this directly

Calls 2

openMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected