Skip to content

Instantly share code, notes, and snippets.

@magurosan
Last active January 7, 2020 15:20
Show Gist options
  • Save magurosan/0590336fec74a5412072abf9f7f1183e to your computer and use it in GitHub Desktop.
Save magurosan/0590336fec74a5412072abf9f7f1183e to your computer and use it in GitHub Desktop.
PNG(8-bit RGBA) texture file masking tool for VRoid Studio
#include <iostream>
#include <png++/png.hpp>
int main(int argc, char *argv[])
{
if (argc != 4) {
std::cerr << "usage: " << argv[0] << " [source.png] [mask.png] [dest.png]\n";
return 1;
}
try {
png::image <png::rgba_pixel> image(argv[1]), msk(argv[2]);
if (image.get_width() != msk.get_width() || image.get_height() != msk.get_height()) {
std::cerr << "both pixels size are mismatched\n";
return 1;
}
// copy alpha
for (size_t x = 0; x < image.get_width(); ++x) {
for (size_t y = 0; y < image.get_height(); ++y) {
image[y][x].alpha = image[y][x].alpha * (msk[y][x].alpha + 1) / 256;
}
}
image.write(argv[3]);
} catch (png::error& error) {
std::cerr << error.what() << "\n";
return 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment