diff --git a/src/common/mat.h b/src/common/mat.h index 4cc7cc5..f3c43f1 100644 --- a/src/common/mat.h +++ b/src/common/mat.h @@ -73,6 +73,11 @@ public: const std::vector &getData() const { return data; } std::vector &getData() { return data; } + auto begin() { return data.begin(); } + auto end() { return data.end(); } + auto begin() const { return data.begin(); } + auto end() const { return data.end(); } + // left/right mat mirror() { diff --git a/src/mmp_extractor/mmp.cpp b/src/mmp_extractor/mmp.cpp index cd09ef4..092d49d 100644 --- a/src/mmp_extractor/mmp.cpp +++ b/src/mmp_extractor/mmp.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -352,6 +353,27 @@ void mmp::writeColorMap() write_mat_bmp(fn, colormap); } +void mmp::writeSplitColormap() const +{ + std::unordered_set colors; + for (auto &pixel : colormap) + colors.insert(pixel); + for (auto &color : colors) + { + auto m = colormap; + for (auto &pixel : m) + pixel = pixel == color ? 0x0000FF00 : 0; + auto fn = filename; + std::ostringstream ss; + ss << "0x"; + ss.fill('0'); + ss.width(8); + ss << std::hex << std::uppercase << color; + fn += ".colormap." + ss.str() + ".bmp"; + write_mat_bmp(fn, m); + } +} + void mmp::writeShadowMap() { auto fn = filename; diff --git a/src/mmp_extractor/mmp.h b/src/mmp_extractor/mmp.h index f685093..5b7a02e 100644 --- a/src/mmp_extractor/mmp.h +++ b/src/mmp_extractor/mmp.h @@ -203,4 +203,5 @@ struct mmp void writeColorMap(); void writeShadowMap(); void writeNormalMap(); + void writeSplitColormap() const; }; diff --git a/src/mmp_extractor/mmp_extractor.cpp b/src/mmp_extractor/mmp_extractor.cpp index ee344fb..e212824 100644 --- a/src/mmp_extractor/mmp_extractor.cpp +++ b/src/mmp_extractor/mmp_extractor.cpp @@ -34,10 +34,11 @@ int main(int argc, char *argv[]) { cl::opt p(cl::Positional, cl::desc(""), cl::Required); cl::opt texture_ids(cl::Positional, cl::desc("")); + cl::opt split_colormap("split_colormap", cl::desc("split colormap into separate images")); cl::ParseCommandLineOptions(argc, argv); - auto func = [&texture_ids](auto &p) + auto func = [&texture_ids, &split_colormap](auto &p) { mmp m; if (!texture_ids.empty()) @@ -54,6 +55,8 @@ int main(int argc, char *argv[]) m.writeColorMap(); m.writeShadowMap(); m.writeNormalMap(); + if (split_colormap) + m.writeSplitColormap(); }; if (fs::is_regular_file(p))