First commit.

This commit is contained in:
2023-12-17 03:29:08 -08:00
commit 09ced8e899
255 changed files with 45001 additions and 0 deletions

178
include/IO/Img/Img.h Normal file
View File

@@ -0,0 +1,178 @@
#pragma once
#include "../../EHS.h"
#include "../../Str.h"
#include "ImgCodec.h"
namespace lwe
{
enum class Resampling : UInt_8
{
NONE,
NEAREST_NEIGHBOR
};
class Img
{
private:
static Array<ImgCodec> codecs;
protected:
UInt_8 bitDepth;
UInt_8 channels;
UInt_64 width;
UInt_64 height;
UInt_64 size;
Byte* data;
public:
static bool HasCodec(UInt_64 hashExt);
static bool HasCodec(const Str_8& ext);
static bool AddCodec(ImgCodec codec);
static const ImgCodec* GetCodec(UInt_64 hashExt);
static const ImgCodec* GetCodec(const Str_8& ext);
~Img();
Img();
Img(UInt_8 bitDepth, UInt_8 channels, UInt_64 width, UInt_64 height, const Byte* data);
Img(UInt_8 bitDepth, UInt_8 channels, UInt_64 width, UInt_64 height);
Img(Img&& img) noexcept;
Img(const Img& img);
Img& operator=(Img&& img) noexcept;
Img& operator=(const Img& img);
operator const Byte* () const;
operator Byte* ();
void Release();
UInt_8 BitDepth() const;
UInt_8 Channels() const;
UInt_64 Width() const;
UInt_64 Height() const;
UInt_64 Size() const;
void SetPixel(UInt_64 index, const Byte* pixel);
void GetPixel(UInt_64 index, Byte* pixel) const;
void SetPixel(UInt_64 x, UInt_64 y, const Byte* pixel);
void GetPixel(UInt_64 x, UInt_64 y, Byte* pixel) const;
void Resize(Resampling method, UInt_64 newWidth, UInt_64 newHeight);
Img GetResized(Resampling method, UInt_64 newWidth, UInt_64 newHeight) const;
void ToRGBA();
Img GetAsRGBA() const;
void ToRGB();
Img GetAsRGB() const;
void ToMonoA();
Img GetAsMonoA() const;
void ToMono();
Img GetAsMono() const;
void To32();
Img GetAs32() const;
void To24();
Img GetAs24() const;
void To16();
Img GetAs16() const;
void To8();
Img GetAs8() const;
bool IsValid() const;
bool ToFile(const Str_8& filePath) const;
static Img FromFile(const Str_8& filePath);
static Img* FromFile_Heap(const Str_8& filePath);
static Img FromData(const Str_8& ext, Serializer<UInt_64>& data);
private:
Img GetNearestNeighbor(UInt_64 newWidth, UInt_64 newHeight) const;
void NearestNeighbor(UInt_64 newWidth, UInt_64 newHeight);
void RGB_To_RGBA(UInt_64 newSize, Byte* buffer) const;
void MonoA_To_RGBA(UInt_64 newSize, Byte* buffer) const;
void Mono_To_RGBA(UInt_64 newSize, Byte* buffer) const;
void RGBA_To_RGB(UInt_64 newSize, Byte* buffer) const;
void MonoA_To_RGB(UInt_64 newSize, Byte* buffer) const;
void Mono_To_RGB(UInt_64 newSize, Byte* buffer) const;
void RGBA_To_MonoA(UInt_64 newSize, Byte* buffer) const;
void RGB_To_MonoA(UInt_64 newSize, Byte* buffer) const;
void Mono_To_MonoA(UInt_64 newSize, Byte* buffer) const;
void RGBA_To_Mono(UInt_64 newSize, Byte* buffer) const;
void RGB_To_Mono(UInt_64 newSize, Byte* buffer) const;
void MonoA_To_Mono(UInt_64 newSize, Byte* buffer) const;
void BD24_to_BD32(UInt_64 newSize, Byte* buffer) const;
void BD16_to_BD32(UInt_64 newSize, Byte* buffer) const;
void BD8_to_BD32(UInt_64 newSize, Byte* buffer) const;
void BD32_to_BD24(UInt_64 newSize, Byte* buffer) const;
void BD16_to_BD24(UInt_64 newSize, Byte* buffer) const;
void BD8_to_BD24(UInt_64 newSize, Byte* buffer) const;
void BD32_to_BD16(UInt_64 newSize, Byte* buffer) const;
void BD24_to_BD16(UInt_64 newSize, Byte* buffer) const;
void BD8_to_BD16(UInt_64 newSize, Byte* buffer) const;
void BD32_to_BD8(UInt_64 newSize, Byte* buffer) const;
void BD24_to_BD8(UInt_64 newSize, Byte* buffer) const;
void BD16_to_BD8(UInt_64 newSize, Byte* buffer) const;
};
}

48
include/IO/Img/ImgCodec.h Normal file
View File

@@ -0,0 +1,48 @@
#pragma once
#include "../../EHS.h"
#include "../../Str.h"
#include "../File.h"
namespace lwe
{
class Img;
class ImgCodec
{
private:
Str_8 id;
UInt_64 hashExt;
Str_8 ext;
Endianness endianness;
bool (*encodeCb)(const ImgCodec* const, Serializer<UInt_64>&, const Img*);
bool (*decodeCb)(const ImgCodec* const, Serializer<UInt_64>&, Img*);
public:
ImgCodec();
ImgCodec(Str_8 id, Str_8 ext, const Endianness end,
bool (*encodeCb)(const ImgCodec* const, Serializer<UInt_64>&, const Img*),
bool (*decodeCb)(const ImgCodec* const, Serializer<UInt_64>&, Img*));
ImgCodec(ImgCodec&& codec) noexcept;
ImgCodec(const ImgCodec& codec);
ImgCodec& operator=(ImgCodec&& codec) noexcept;
ImgCodec& operator=(const ImgCodec& codec);
Str_8 GetId() const;
UInt_64 GetHashExt() const;
Str_8 GetExt() const;
Endianness GetEndianness() const;
bool Encode(Serializer<UInt_64>& out, const Img* in) const;
bool Decode(Serializer<UInt_64>& in, Img* out) const;
};
}

51
include/IO/Img/PNG.h Normal file
View File

@@ -0,0 +1,51 @@
#pragma once
#include "../../EHS.h"
#include "../../Serializer.h"
#include "PNG_Chunk.h"
#include "Img.h"
namespace lwe
{
class PNG
{
private:
Str_8 id;
UInt_64 hashId;
Array<PNG_Chunk> chunks;
public:
PNG();
PNG(const Str_8& filePath);
PNG(const Str_8& id, Serializer<UInt_64>& data);
PNG(const PNG& png);
PNG& operator=(const PNG& png);
bool HasChunk(const UInt_64 hashId) const;
bool HasChunk(const Str_8& id) const;
PNG_Chunk* GetChunk(const UInt_64 hashId);
PNG_Chunk* GetChunk(const Str_8& id);
static bool IsPNG(Serializer<UInt_32>& data);
static void FilterNone(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
static void FilterSub(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
static void FilterUp(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
static void FilterAverage(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
static void FilterPaeth(const Byte* const in, Byte* const out, const UInt_8 bitDepth, const UInt_8 channels, const UInt_32 scanline);
private:
static Byte PaethPredictor(const Byte a, const Byte b, const Byte c);
};
}

View File

@@ -0,0 +1,34 @@
#pragma once
#include "../../EHS.h"
#include "../../Str.h"
#include "../../Serializer.h"
namespace lwe
{
class PNG_Chunk
{
private:
Str_8 id;
UInt_64 hashId;
Serializer<UInt_64> data;
Byte crc[4];
public:
PNG_Chunk();
PNG_Chunk(const Str_8& id, const Serializer<UInt_64>& data, const Byte crc[4]);
PNG_Chunk(const PNG_Chunk& chunk);
PNG_Chunk& operator=(const PNG_Chunk& chunk);
Str_8 GetId() const;
UInt_64 GetHashId() const;
Serializer<UInt_64>* GetData();
const unsigned char* GetCRC() const;
};
}