2023-12-17 03:29:08 -08:00
|
|
|
#pragma once
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
#include "Types.h"
|
|
|
|
#include "BaseObj.h"
|
2023-12-17 15:00:08 -08:00
|
|
|
#include "Str.h"
|
2023-12-17 03:29:08 -08:00
|
|
|
#include "ImgCodec.h"
|
|
|
|
|
2023-12-17 15:56:13 -08:00
|
|
|
namespace ehs
|
2023-12-17 03:29:08 -08:00
|
|
|
{
|
|
|
|
enum class Resampling : UInt_8
|
|
|
|
{
|
|
|
|
NONE,
|
|
|
|
NEAREST_NEIGHBOR
|
|
|
|
};
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
class Img : public BaseObj
|
2023-12-17 03:29:08 -08:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
static Array<ImgCodec> codecs;
|
|
|
|
|
|
|
|
protected:
|
2023-12-18 02:13:20 -08:00
|
|
|
UInt_64 hashId;
|
|
|
|
Str_8 id;
|
2023-12-17 03:29:08 -08:00
|
|
|
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();
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Img(Str_8 id);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
Img(Str_8 id, UInt_8 bitDepth, UInt_8 channels, UInt_64 width, UInt_64 height, const Byte* data);
|
|
|
|
|
|
|
|
Img(Str_8 id, UInt_8 bitDepth, UInt_8 channels, UInt_64 width, UInt_64 height);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
UInt_64 GetHashId() const;
|
|
|
|
|
|
|
|
void SetId(Str_8 newId);
|
|
|
|
|
|
|
|
Str_8 GetId() const;
|
|
|
|
|
2023-12-17 03:29:08 -08:00
|
|
|
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);
|
|
|
|
|
2023-12-18 02:13:20 -08:00
|
|
|
static Img FromData(Str_8 id, const Str_8& ext, Serializer<UInt_64>& data);
|
2023-12-17 03:29:08 -08:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
}
|