snake-vhdl/sprites/png2hex.cpp
2021-12-22 00:35:26 +01:00

35 lines
894 B
C++

#include "CLI/App.hpp"
#include "CLI/Formatter.hpp"
#include "CLI/Config.hpp"
#include <iostream>
#include <png++/png.hpp>
int main(int argc,char* argv[]){
CLI::App app{"png2hex"};
std::string filename = "";
app.add_option("-f,--file", filename, "PNG image file")->required();
CLI11_PARSE(app,argc,argv);
png::image<png::rgba_pixel> image(filename);
std::cout << std::hex << std::uppercase << std::setfill('0') << std::setw(6);
for (png::uint_32 y = 0; y < image.get_height(); ++y){
for (png::uint_32 x = 0; x < image.get_width(); ++x){
unsigned int pxl=0; //On peut raisonnablement esperer que int puisse stocker 24bits
png::rgba_pixel p=image[y][x];
int ps=sizeof(p.red)*8;
pxl=p.red>>(ps-5);
pxl=pxl<<6 | (p.green>>(ps-6));
pxl=pxl<<5 | (p.blue>>(ps-5));
pxl=pxl<<8 | (p.alpha>>(ps-8));
std::cout << std::setw(6) << pxl << '\n';
}
}
return 1;
}