summaryrefslogtreecommitdiffhomepage
path: root/wall-tileset-tool/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'wall-tileset-tool/main.cpp')
-rw-r--r--wall-tileset-tool/main.cpp100
1 files changed, 46 insertions, 54 deletions
diff --git a/wall-tileset-tool/main.cpp b/wall-tileset-tool/main.cpp
index a7fc0b6e..128b21d2 100644
--- a/wall-tileset-tool/main.cpp
+++ b/wall-tileset-tool/main.cpp
@@ -166,73 +166,65 @@ bool do_group(state st, size_t i, size_t j, Group& new_group)
new_group.is_defined = true;
new_group.pixel_size = Vector2ui(expected_size);
- if (old_group.from_rotation == (uint8_t)-1)
+ for (;;)
{
- for (;;)
+ auto filename = asformat("{}/{:04}.png"_cf, path, count+1);
+ if (!Path::exists(filename))
+ break;
+ count++;
+ if (Path::isDirectory(filename)) [[unlikely]]
{
- auto filename = asformat("{}/{:04}.png"_cf, path, count+1);
- if (!Path::exists(filename))
- break;
- count++;
- if (Path::isDirectory(filename)) [[unlikely]]
- {
- ERR << "fatal: path" << quoted(filename) << "is a directory!";
- return false;
- }
-
- cv::Mat mat = cv::imread(filename, cv::IMREAD_ANYCOLOR), mat2;
- if ((Group_)j == Group_::top)
- {
- cv::rotate(mat, mat2, cv::ROTATE_90_COUNTERCLOCKWISE);
- using std::swap;
- swap(mat, mat2);
- }
-
- const auto size = Vector2ui{(unsigned)mat.cols, (unsigned)mat.rows};
-
- if (size != expected_size) [[unlikely]]
- {
- ERR << "fatal: wrong image size, expected"
- << resolution{expected_size} << colon(',')
- << "actual" << resolution{size}
- << "-- file" << filename;
- return false;
- }
-
- cv::Mat4b buf;
- if (mat.channels() == 4)
- st.opts.use_alpha = true;
- if (!convert_to_bgra32(mat, buf)) [[unlikely]]
- {
- ERR << "fatal: unknown image pixel format:"
- << "channels" << mat.channels() << colon(',')
- << "depth" << cv::depthToString(mat.depth()) << colon(',')
- << "type" << cv::typeToString(mat.type()) << colon(',')
- << "for" << quoted(filename);
- return false;
- }
-
- st.frames.push_back({.mat = std::move(buf)});
+ ERR << "fatal: path" << quoted(filename) << "is a directory!";
+ return false;
}
- if (count == 0)
+ cv::Mat mat = cv::imread(filename, cv::IMREAD_ANYCOLOR), mat2;
+ if ((Group_)j == Group_::top)
{
- ERR << "fatal: no files found for" << quoted2(dir_name) << "/" << quoted2(group_name);
+ cv::rotate(mat, mat2, cv::ROTATE_90_COUNTERCLOCKWISE);
+ using std::swap;
+ swap(mat, mat2);
+ }
+
+ const auto size = Vector2ui{(unsigned)mat.cols, (unsigned)mat.rows};
+
+ if (size != expected_size) [[unlikely]]
+ {
+ ERR << "fatal: wrong image size, expected"
+ << resolution{expected_size} << colon(',')
+ << "actual" << resolution{size}
+ << "-- file" << filename;
return false;
}
- DBG << " " << Debug::nospace << count << (count == 1 ? "frame" : "frames");
+ cv::Mat4b buf;
+ if (mat.channels() == 4)
+ st.opts.use_alpha = true;
+ if (!convert_to_bgra32(mat, buf)) [[unlikely]]
+ {
+ ERR << "fatal: unknown image pixel format:"
+ << "channels" << mat.channels() << colon(',')
+ << "depth" << cv::depthToString(mat.depth()) << colon(',')
+ << "type" << cv::typeToString(mat.type()) << colon(',')
+ << "for" << quoted(filename);
+ return false;
+ }
- fm_assert(start + count == st.frames.size());
- new_group.count = count;
- new_group.index = start;
+ st.frames.push_back({.mat = std::move(buf)});
}
- else
+
+ if (count == 0)
{
- new_group.count = 0;
- new_group.index = (uint32_t)-1;
+ ERR << "fatal: no files found for" << quoted2(dir_name) << "/" << quoted2(group_name);
+ return false;
}
+ DBG << " " << Debug::nospace << count << (count == 1 ? "frame" : "frames");
+
+ fm_assert(start + count == st.frames.size());
+ new_group.count = count;
+ new_group.index = start;
+
return true;
}