Adjusted workflow.
This commit is contained in:
188
include/ehs/io/img/Img.h
Normal file
188
include/ehs/io/img/Img.h
Normal file
@@ -0,0 +1,188 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/Types.h"
|
||||
#include "ehs/BaseObj.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ImgCodec.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
enum class Resampling : UInt_8
|
||||
{
|
||||
NONE,
|
||||
NEAREST_NEIGHBOR
|
||||
};
|
||||
|
||||
class Img : public BaseObj
|
||||
{
|
||||
private:
|
||||
static Array<ImgCodec> codecs;
|
||||
|
||||
protected:
|
||||
UInt_64 hashId;
|
||||
Str_8 id;
|
||||
UInt_8 byteDepth;
|
||||
UInt_8 channels;
|
||||
Vec2_u64 resolution;
|
||||
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() override;
|
||||
|
||||
Img();
|
||||
|
||||
Img(Str_8 id);
|
||||
|
||||
Img(Str_8 id, UInt_8 byteDepth, UInt_8 channels, const Vec2_u64& resolution, const Byte* data);
|
||||
|
||||
Img(Str_8 id, UInt_8 byteDepth, UInt_8 channels, const Vec2_u64& resolution);
|
||||
|
||||
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_64 GetHashId() const;
|
||||
|
||||
void SetId(Str_8 newId);
|
||||
|
||||
Str_8 GetId() const;
|
||||
|
||||
UInt_8 GetByteDepth() const;
|
||||
|
||||
UInt_8 GetBitDepth() const;
|
||||
|
||||
UInt_8 GetChannels() const;
|
||||
|
||||
Vec2_u64 GetResolution() const;
|
||||
|
||||
UInt_64 GetSize() 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, const Vec2_u64& newResolution);
|
||||
|
||||
Img GetResized(Resampling method, const Vec2_u64& newResolution) 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(Str_8 id, const Str_8& ext, Serializer<UInt_64>& data);
|
||||
|
||||
private:
|
||||
Img GetNearestNeighbor(const Vec2_u64& newResolution) const;
|
||||
|
||||
void NearestNeighbor(const Vec2_u64& newResolution);
|
||||
|
||||
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/ehs/io/img/ImgCodec.h
Normal file
48
include/ehs/io/img/ImgCodec.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/io/File.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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/ehs/io/img/PNG.h
Normal file
51
include/ehs/io/img/PNG.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Serializer.h"
|
||||
#include "PNG_Chunk.h"
|
||||
#include "Img.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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);
|
||||
};
|
||||
}
|
34
include/ehs/io/img/PNG_Chunk.h
Normal file
34
include/ehs/io/img/PNG_Chunk.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "ehs/EHS.h"
|
||||
#include "ehs/Str.h"
|
||||
#include "ehs/Serializer.h"
|
||||
|
||||
namespace ehs
|
||||
{
|
||||
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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user