#pragma once #include #include #include #include class Image { public: std::shared_ptr data = nullptr; uint32_t width; uint32_t height; uint8_t channels; const uint32_t size() { return width*height*channels; } void save(const char* filename) { std::ofstream outfile(filename); outfile.write((char *) data.get(), size()); outfile.close(); } bool open(const char* filename, const uint32_t widthI, const uint32_t heightI, const uint32_t channelsI) { height = heightI; width = widthI; channels = channelsI; std::ifstream infile( filename, std::ios::binary); if(!infile.is_open() || infile.bad()) return false; infile.seekg (0, infile.end); uint32_t filelength = infile.tellg(); infile.seekg (0, infile.beg); if(filelength != size()) return false; data = std::shared_ptr(new unsigned char[filelength]); infile.read((char*)data.get(), filelength); infile.close(); return true; } };