EHS/include/IO/Img/Img.h
2023-12-17 03:29:08 -08:00

179 lines
3.5 KiB
C++

#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;
};
}