intial commit

This commit is contained in:
2023-11-18 14:07:27 +01:00
commit ce321a6e33
9 changed files with 781 additions and 0 deletions

43
image.h Normal file
View File

@ -0,0 +1,43 @@
#pragma once
#include <fstream>
#include <iostream>
#include <cstdint>
#include <memory>
class Image
{
public:
std::shared_ptr<unsigned char> 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<unsigned char>(new unsigned char[filelength]);
infile.read((char*)data.get(), filelength);
infile.close();
return true;
}
};