Add split colormap option.

This commit is contained in:
lzwdgc 2018-08-02 01:56:52 +03:00
parent f900353090
commit bdf5e9ff37
4 changed files with 32 additions and 1 deletions

View file

@ -73,6 +73,11 @@ public:
const std::vector<T> &getData() const { return data; }
std::vector<T> &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()
{

View file

@ -23,6 +23,7 @@
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <primitives/filesystem.h>
@ -352,6 +353,27 @@ void mmp::writeColorMap()
write_mat_bmp(fn, colormap);
}
void mmp::writeSplitColormap() const
{
std::unordered_set<uint32_t> 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;

View file

@ -203,4 +203,5 @@ struct mmp
void writeColorMap();
void writeShadowMap();
void writeNormalMap();
void writeSplitColormap() const;
};

View file

@ -34,10 +34,11 @@ int main(int argc, char *argv[])
{
cl::opt<path> p(cl::Positional, cl::desc("<file.mmp or directory>"), cl::Required);
cl::opt<path> texture_ids(cl::Positional, cl::desc("<path to texture_ids.txt>"));
cl::opt<bool> 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))