diff --git a/include/ehs/io/BaseFile.h b/include/ehs/io/BaseFile.h index a79127c..cadbbb8 100644 --- a/include/ehs/io/BaseFile.h +++ b/include/ehs/io/BaseFile.h @@ -239,22 +239,22 @@ namespace ehs static void Rename_8(const Str_8& filePath, const Str_8& newName); - static Str_32 ProcessFullName_32(const Str_32& filePath); + static Str_32 ParseFullName_32(const Str_32& filePath); - static Str_16 ProcessFullName_16(const Str_16& filePath); + static Str_16 ParseFullName_16(const Str_16& filePath); - static Str_8 ProcessFullName_8(const Str_8& filePath); + static Str_8 ParseFullName_8(const Str_8& filePath); - static Str_32 ProcessName_32(const Str_32& filePath); + static Str_32 ParseName_32(const Str_32& filePath); - static Str_16 ProcessName_16(const Str_16& filePath); + static Str_16 ParseName_16(const Str_16& filePath); - static Str_8 ProcessName_8(const Str_8& filePath); + static Str_8 ParseName_8(const Str_8& filePath); - static Str_32 ProcessExt_32(const Str_32& filePath); + static Str_32 ParseExt_32(const Str_32& filePath); - static Str_16 ProcessExt_16(const Str_16& filePath); + static Str_16 ParseExt_16(const Str_16& filePath); - static Str_8 ProcessExt_8(const Str_8& filePath); + static Str_8 ParseExt_8(const Str_8& filePath); }; } diff --git a/include/ehs/io/FontAtlas.h b/include/ehs/io/FontAtlas.h index 04ac4ef..65f9286 100644 --- a/include/ehs/io/FontAtlas.h +++ b/include/ehs/io/FontAtlas.h @@ -10,13 +10,20 @@ namespace ehs { - class FontAtlas : public Img + class FontAtlas : public BaseObj { private: + UInt_64 hashId; + Str_8 id; UInt_64 glyphScale; Array glyphs; + Vec2_u64 resolution; + UInt_64 size; + Byte* atlas; public: + ~FontAtlas() override; + FontAtlas(); FontAtlas(const Str_8& filePath); @@ -29,10 +36,24 @@ namespace ehs FontAtlas& operator=(const FontAtlas& fa); + operator Byte*() const; + + void Release(); + + UInt_64 GetHashId() const; + + Str_8 GetId() const; + UInt_64 GetGlyphScale() const; Glyph GetGlyph(Char_32 code) const; + Vec2_u64 GetResolution() const; + + UInt_64 GetSize() const; + + bool IsValid() const; + Vec2_f CalculateSize(const Str_8& text) const; float CalculateWidth(const Str_8& text) const; diff --git a/include/ehs/io/img/Img.h b/include/ehs/io/img/Img.h index 2d21003..05b2759 100644 --- a/include/ehs/io/img/Img.h +++ b/include/ehs/io/img/Img.h @@ -21,10 +21,9 @@ namespace ehs protected: UInt_64 hashId; Str_8 id; - UInt_8 bitDepth; + UInt_8 byteDepth; UInt_8 channels; - UInt_64 width; - UInt_64 height; + Vec2_u64 resolution; UInt_64 size; Byte* data; @@ -39,15 +38,15 @@ namespace ehs static const ImgCodec* GetCodec(const Str_8& ext); - ~Img(); + ~Img() override; Img(); Img(Str_8 id); - 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 byteDepth, UInt_8 channels, const Vec2_u64& resolution, const Byte* data); - Img(Str_8 id, UInt_8 bitDepth, UInt_8 channels, UInt_64 width, UInt_64 height); + Img(Str_8 id, UInt_8 byteDepth, UInt_8 channels, const Vec2_u64& resolution); Img(Img&& img) noexcept; @@ -69,15 +68,15 @@ namespace ehs Str_8 GetId() const; - UInt_8 BitDepth() const; + UInt_8 GetByteDepth() const; - UInt_8 Channels() const; + UInt_8 GetBitDepth() const; - UInt_64 Width() const; + UInt_8 GetChannels() const; - UInt_64 Height() const; + Vec2_u64 GetResolution() const; - UInt_64 Size() const; + UInt_64 GetSize() const; void SetPixel(UInt_64 index, const Byte* pixel); @@ -87,9 +86,9 @@ namespace ehs void GetPixel(UInt_64 x, UInt_64 y, Byte* pixel) const; - void Resize(Resampling method, UInt_64 newWidth, UInt_64 newHeight); + void Resize(Resampling method, const Vec2_u64& newResolution); - Img GetResized(Resampling method, UInt_64 newWidth, UInt_64 newHeight) const; + Img GetResized(Resampling method, const Vec2_u64& newResolution) const; void ToRGBA(); @@ -134,9 +133,9 @@ namespace ehs static Img FromData(Str_8 id, const Str_8& ext, Serializer& data); private: - Img GetNearestNeighbor(UInt_64 newWidth, UInt_64 newHeight) const; + Img GetNearestNeighbor(const Vec2_u64& newResolution) const; - void NearestNeighbor(UInt_64 newWidth, UInt_64 newHeight); + void NearestNeighbor(const Vec2_u64& newResolution); void RGB_To_RGBA(UInt_64 newSize, Byte* buffer) const; diff --git a/include/ehs/io/model/Bone.h b/include/ehs/io/model/Bone.h index da3393b..32844f8 100644 --- a/include/ehs/io/model/Bone.h +++ b/include/ehs/io/model/Bone.h @@ -20,7 +20,7 @@ namespace ehs public: Bone(); - Bone(Str_8 name, const UInt_8 id, const Mat4_f& localBindTrans, const Mat4_f& invBindTrans); + Bone(Str_8 name, UInt_8 id, const Mat4_f& localBindTrans, const Mat4_f& invBindTrans); Bone(Bone&& bone) noexcept; @@ -50,21 +50,21 @@ namespace ehs UInt_8 GetBoneCount() const; - bool HasBone(const UInt_64 hashName, const UInt_8 id) const; + bool HasBone(UInt_64 hashName, UInt_8 id) const; - bool HasBone(const UInt_64 hashName) const; + bool HasBone(UInt_64 hashName) const; - bool HasBone(const UInt_8 id) const; + bool HasBone(UInt_8 id) const; bool AddBone(Bone child); - const Bone* GetBone(const UInt_64 hashName) const; + const Bone* GetBone(UInt_64 hashName) const; - Bone* GetBone(const UInt_64 hashName); + Bone* GetBone(UInt_64 hashName); - const Bone* GetBone(const UInt_8 id) const; + const Bone* GetBone(UInt_8 id) const; - Bone* GetBone(const UInt_8 id); + Bone* GetBone(UInt_8 id); const Array& GetChildren() const; diff --git a/include/ehs/io/model/Mesh.h b/include/ehs/io/model/Mesh.h index bd9a5e1..af3421c 100644 --- a/include/ehs/io/model/Mesh.h +++ b/include/ehs/io/model/Mesh.h @@ -7,38 +7,6 @@ namespace ehs { - const Array portraitGuiVerts({ - {{0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}}, - {{0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f}}, - {{1.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 0.0f}}, - {{1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 1.0f}} - }); - - const Array portraitGuiIndices({ - 0, - 1, - 2, - 3, - 2, - 1 - }); - - const Array portraitVerts({ - {{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}}, - {{-0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f}}, - {{0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 0.0f}}, - {{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 1.0f}} - }); - - const Array portraitIndices({ - 0, - 1, - 2, - 3, - 2, - 1 - }); - class Mesh final : public BaseObj { protected: @@ -89,4 +57,24 @@ namespace ehs private: static void Calculate(Vertex_f& vert1, Vertex_f& vert2, Vertex_f& vert3); }; + + const Mesh portraitGui("PortraitGui", + { + {{0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}}, + {{0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f}}, + {{1.0f, 0.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 0.0f}}, + {{1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 1.0f}} + }, + {0, 1, 2, 3, 2, 1} + ); + + const Mesh portrait("Portrait", + { + {{-0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 0.0f}}, + {{-0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {0.0f, 1.0f}}, + {{0.5f, -0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 0.0f}}, + {{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, -1.0f}, {1.0f, 1.0f}} + }, + {0, 1, 2, 3, 2, 1} + ); } \ No newline at end of file diff --git a/include/ehs/io/model/Model.h b/include/ehs/io/model/Model.h index 357e201..1bc3488 100644 --- a/include/ehs/io/model/Model.h +++ b/include/ehs/io/model/Model.h @@ -50,7 +50,7 @@ namespace ehs Str_8 GetId() const; - Array GetMeshes() const; + const Array& GetMeshes() const; Array& GetMeshes(); @@ -58,13 +58,13 @@ namespace ehs Mesh* GetMesh(const Str_8& inId); - Bone GetSkeleton() const; + const Bone& GetSkeleton() const; Bone& GetSkeleton(); Animation* GetAnimation(UInt_64 inHashId); - Array GetAnimations() const; + const Array& GetAnimations() const; Array& GetAnimations(); diff --git a/src/EHS.cpp b/src/EHS.cpp index c8bfe1e..e2a49a7 100644 --- a/src/EHS.cpp +++ b/src/EHS.cpp @@ -329,7 +329,7 @@ namespace ehs else if (colorType == 6) channels = 4; - *out = Img(out->GetId(), bitDepth, channels, width, height); + *out = Img(out->GetId(), bitDepth, channels, {width, height}); UInt_8 compression = ihdrData->Read(); if (compression) @@ -419,11 +419,10 @@ namespace ehs bool EncodeQOI(const ehs::ImgCodec* const codec, ehs::Serializer& out, const ehs::Img* in) { - UInt_8 channels = in->Channels(); - UInt_64 width = in->Width(); - UInt_64 height = in->Height(); + UInt_8 channels = in->GetChannels(); + Vec2_u64 resolution = in->GetResolution(); - UInt_32 px_len = width * height * channels; + UInt_32 px_len = resolution.x * resolution.y * channels; UInt_32 px_end = px_len - channels; Byte index[256]; @@ -433,15 +432,15 @@ namespace ehs Byte prevPixel[4] = {0, 0, 0, 255}; Byte pixel[4] = {0, 0, 0, 255}; - Serializer result(Endianness::BE, width * height * (channels + 1) + 22); + Serializer result(Endianness::BE, resolution.x * resolution.y * (channels + 1) + 22); result.Write('q'); result.Write('o'); result.Write('i'); result.Write('f'); - result.Write(width); - result.Write(height); - result.Write(in->Channels()); + result.Write(resolution.x); + result.Write(resolution.y); + result.Write(in->GetChannels()); result.Write(1); for (UInt_32 px_pos = 0, run = 0; px_pos < px_len; px_pos += channels) @@ -555,7 +554,7 @@ namespace ehs UInt_64 size = width * channels * height; - *out = Img(out->GetId(), bitDepth, channels, width, height); + *out = Img(out->GetId(), bitDepth, channels, {width, height}); Byte prevPixel[4] = {0, 0, 0, 255}; diff --git a/src/io/BaseFile.cpp b/src/io/BaseFile.cpp index 21db9ac..4362cda 100644 --- a/src/io/BaseFile.cpp +++ b/src/io/BaseFile.cpp @@ -8,8 +8,8 @@ namespace ehs } BaseFile::BaseFile(const Str_8& filePath, const Mode mode, const Disposition disposition) - : path(filePath), fullName(ProcessFullName_8(filePath)), - name(ProcessName_8(fullName)), extension(ProcessExt_8(fullName)), + : path(filePath), fullName(ParseFullName_8(filePath)), + name(ParseName_8(fullName)), extension(ParseExt_8(fullName)), mode(mode), disposition(disposition) { } @@ -506,7 +506,7 @@ namespace ehs { } - Str_32 BaseFile::ProcessFullName_32(const Str_32& filePath) + Str_32 BaseFile::ParseFullName_32(const Str_32& filePath) { UInt_64 index = 0; @@ -516,7 +516,7 @@ namespace ehs return filePath.Sub(index); } - Str_16 BaseFile::ProcessFullName_16(const Str_16& filePath) + Str_16 BaseFile::ParseFullName_16(const Str_16& filePath) { UInt_64 index = 0; @@ -526,7 +526,7 @@ namespace ehs return filePath.Sub(index); } - Str_8 BaseFile::ProcessFullName_8(const Str_8& filePath) + Str_8 BaseFile::ParseFullName_8(const Str_8& filePath) { UInt_64 index = 0; @@ -536,7 +536,7 @@ namespace ehs return filePath.Sub(index); } - Str_32 BaseFile::ProcessName_32(const Str_32& filePath) + Str_32 BaseFile::ParseName_32(const Str_32& filePath) { UInt_64 index; Str_32 file = filePath; @@ -550,7 +550,7 @@ namespace ehs return file.Sub(0, index - 1); } - Str_16 BaseFile::ProcessName_16(const Str_16& filePath) + Str_16 BaseFile::ParseName_16(const Str_16& filePath) { UInt_64 index; Str_16 file = filePath; @@ -564,7 +564,7 @@ namespace ehs return file.Sub(0, index - 1); } - Str_8 BaseFile::ProcessName_8(const Str_8& filePath) + Str_8 BaseFile::ParseName_8(const Str_8& filePath) { UInt_64 index; Str_8 file = filePath; @@ -578,7 +578,7 @@ namespace ehs return file.Sub(0, index - 1); } - Str_32 BaseFile::ProcessExt_32(const Str_32& filePath) + Str_32 BaseFile::ParseExt_32(const Str_32& filePath) { UInt_64 index = 0; @@ -587,7 +587,7 @@ namespace ehs return filePath.Sub(index); } - Str_16 BaseFile::ProcessExt_16(const Str_16& filePath) + Str_16 BaseFile::ParseExt_16(const Str_16& filePath) { UInt_64 index = 0; @@ -596,7 +596,7 @@ namespace ehs return filePath.Sub(index); } - Str_8 BaseFile::ProcessExt_8(const Str_8& filePath) + Str_8 BaseFile::ParseExt_8(const Str_8& filePath) { UInt_64 index = 0; diff --git a/src/io/FontAtlas.cpp b/src/io/FontAtlas.cpp index 764540a..ecf3639 100644 --- a/src/io/FontAtlas.cpp +++ b/src/io/FontAtlas.cpp @@ -4,13 +4,17 @@ namespace ehs { + FontAtlas::~FontAtlas() + { + delete[] atlas; + } + FontAtlas::FontAtlas() - : glyphScale(0) + : hashId(0), glyphScale(0), size(0), atlas(nullptr) { } FontAtlas::FontAtlas(const Str_8& filePath) - : glyphScale(0) { File fontFile(filePath, Mode::READ, Disposition::OPEN); @@ -35,23 +39,28 @@ namespace ehs for (UInt_64 i = 0; i < glyphs.Size(); ++i) glyphs[i] = Glyph(fData); - bitDepth = 8; - channels = 1; - width = fData.Read(); - height = fData.Read(); - data = new Byte[width * height * (bitDepth / 8) * channels]; - fData.ReadArray(data, &size); + resolution = fData.ReadVec2(); + size = resolution.x * resolution.y; + atlas = new Byte[size]; + fData.ReadArray(atlas, &size); } FontAtlas::FontAtlas(FontAtlas&& fa) noexcept - : Img(std::move(fa)), glyphScale(fa.glyphScale), glyphs(std::move(fa.glyphs)) + : BaseObj(std::move(fa)), hashId(fa.hashId), id((Str_8&&)fa.id), glyphScale(fa.glyphScale), + glyphs((Array&&)fa.glyphs), resolution(fa.resolution), size(fa.size), atlas(fa.atlas) { + fa.hashId = 0; fa.glyphScale = 0; + fa.resolution = {}; + fa.size = 0; + fa.atlas = nullptr; } FontAtlas::FontAtlas(const FontAtlas& fa) - : Img(fa), glyphScale(0) + : BaseObj(fa), hashId(fa.hashId), id(fa.id), glyphScale(fa.glyphScale), glyphs(fa.glyphs), + resolution(fa.resolution), size(fa.size), atlas(new Byte[fa.size]) { + Util::Copy(atlas, fa.atlas, fa.size); } FontAtlas& FontAtlas::operator=(FontAtlas&& fa) noexcept @@ -59,12 +68,22 @@ namespace ehs if (this == &fa) return *this; - Img::operator=(std::move(fa)); + BaseObj::operator=(std::move(fa)); + hashId = fa.hashId; + id = (Str_8&&)fa.id; glyphScale = fa.glyphScale; - glyphs = std::move(fa.glyphs); + glyphs = (Array&&)fa.glyphs; + resolution = fa.resolution; + size = fa.size; + delete[] atlas; + atlas = fa.atlas; + fa.hashId = 0; fa.glyphScale = 0; + fa.resolution = {}; + fa.size = 0; + fa.atlas = nullptr; return *this; } @@ -74,14 +93,49 @@ namespace ehs if (this == &fa) return *this; - Img::operator=(fa); + BaseObj::operator=(fa); - glyphScale = 0; - glyphs = Array(); + hashId = fa.hashId; + id = fa.id; + glyphScale = fa.glyphScale; + glyphs = fa.glyphs; + resolution = {}; + size = fa.size; + delete[] atlas; + atlas = new Byte[fa.size]; + + Util::Copy(atlas, fa.atlas, fa.size); return *this; } + FontAtlas::operator Byte *() const + { + return atlas; + } + + void FontAtlas::Release() + { + hashId = 0; + id = {}; + glyphScale = 0; + glyphs.Clear(); + resolution = {0, 0}; + size = 0; + delete[] atlas; + atlas = nullptr; + } + + UInt_64 FontAtlas::GetHashId() const + { + return hashId; + } + + Str_8 FontAtlas::GetId() const + { + return id; + } + UInt_64 FontAtlas::GetGlyphScale() const { return glyphScale; @@ -96,63 +150,78 @@ namespace ehs return glyphs[0]; } + Vec2_u64 FontAtlas::GetResolution() const + { + return resolution; + } + + UInt_64 FontAtlas::GetSize() const + { + return size; + } + + bool FontAtlas::IsValid() const + { + return size; + } + Vec2_f FontAtlas::CalculateSize(const Str_8& text) const { - Vec2_f size; + Vec2_f result; for (UInt_64 i = 0; i < text.Size(); ++i) { Glyph glyph = GetGlyph(text[i]); - size.x += (float)glyph.GetAdvance().x; + result.x += (float)glyph.GetAdvance().x; - if ((float)glyph.GetScale().y > size.y) - size.y = (float)glyph.GetScale().y; + if ((float)glyph.GetScale().y > result.y) + result.y = (float)glyph.GetScale().y; } - return size; + return result; } float FontAtlas::CalculateWidth(const Str_8 &text) const { - float width = 0.0f; + float result = 0.0f; for (UInt_64 i = 0; i < text.Size(); ++i) { Glyph glyph = GetGlyph(text[i]); - width += (float)glyph.GetAdvance().x; + result += (float)glyph.GetAdvance().x; } - return width; + return result; } float FontAtlas::CalculateHeight(const Str_8& text) const { - float height = 0.0f; + float result = 0.0f; for (UInt_64 i = 0; i < text.Size(); ++i) { Glyph glyph = GetGlyph(text[i]); - if ((float)glyph.GetScale().y > height) - height = (float)glyph.GetScale().y; + if ((float)glyph.GetScale().y > result) + result = (float)glyph.GetScale().y; } - return height; + return result; } UInt_64 FontAtlas::CalculateIndexAtPoint(const Str_8& text, const Vec2_f& point) const { - float width = 0.0f; + float result = 0.0f; for (UInt_64 i = 0; i < text.Size(); ++i) { Glyph glyph = GetGlyph(text[i]); - float temp = width + (float)glyph.GetAdvance().x; + float temp = result + (float)glyph.GetAdvance().x; if (point.x > temp) - width += (float)glyph.GetAdvance().x; + result += (float)glyph.GetAdvance().x; else if (point.x <= temp) return i; } @@ -225,6 +294,6 @@ namespace ehs pos.x += (float)glyph.GetAdvance().x; } - return {id, std::move(verts), std::move(indices)}; + return {id, (Array&&)verts, (Array&&)indices}; } } \ No newline at end of file diff --git a/src/io/audio/Audio.cpp b/src/io/audio/Audio.cpp index d67f5c8..0efcb53 100644 --- a/src/io/audio/Audio.cpp +++ b/src/io/audio/Audio.cpp @@ -877,7 +877,7 @@ namespace ehs bool Audio::ToFile(const Str_8& filePath) const { - Str_8 ext = File::ProcessExt_8(filePath); + Str_8 ext = File::ParseExt_8(filePath); const AudioCodec* codec = GetCodec(ext); if (!codec) diff --git a/src/io/img/Img.cpp b/src/io/img/Img.cpp index 34b60f1..df30c9d 100644 --- a/src/io/img/Img.cpp +++ b/src/io/img/Img.cpp @@ -48,48 +48,47 @@ namespace ehs } Img::Img() - : hashId(0), data(nullptr), bitDepth(0), channels(0), width(0), height(0), size(0) + : hashId(0), data(nullptr), byteDepth(0), channels(0), size(0) { AddType("Img"); } - Img::Img(Str_8 id, const UInt_8 bitDepth, const UInt_8 channels, const UInt_64 width, const UInt_64 height, const Byte* const data) - : hashId(id.Hash_64()), id((Str_8&&)id), bitDepth(bitDepth), channels(channels), width(width), height(height), - size(width * (bitDepth / 8) * channels * height), data(new Byte[size]) + Img::Img(Str_8 id, const UInt_8 byteDepth, const UInt_8 channels, const Vec2_u64& resolution, const Byte* const data) + : hashId(id.Hash_64()), id((Str_8&&)id), byteDepth(byteDepth), channels(channels), resolution(resolution), + size(resolution.x * byteDepth * channels * resolution.y), data(new Byte[size]) { Util::Copy(this->data, data, size); AddType("Img"); } - Img::Img(Str_8 id, const UInt_8 bitDepth, const UInt_8 channels, const UInt_64 width, const UInt_64 height) - : hashId(id.Hash_64()), id((Str_8&&)id), bitDepth(bitDepth), channels(channels), width(width), height(height), - size(width * (bitDepth / 8) * channels * height), data(new Byte[size]) + Img::Img(Str_8 id, const UInt_8 byteDepth, const UInt_8 channels, const Vec2_u64& resolution) + : hashId(id.Hash_64()), id((Str_8&&)id), byteDepth(byteDepth), channels(channels), resolution(resolution), + size(resolution.x * byteDepth * channels * resolution.y), data(new Byte[size]) { AddType("Img"); } Img::Img(Str_8 id) - : hashId(id.Hash_64()), id((Str_8&&)id), bitDepth(0), channels(0), width(0), height(0), size(0), data(nullptr) + : hashId(id.Hash_64()), id((Str_8&&)id), byteDepth(0), channels(0), size(0), data(nullptr) { AddType("Img"); } Img::Img(Img&& img) noexcept - : BaseObj((BaseObj&&)img), hashId(img.hashId), id((Str_8&&)img.id), bitDepth(img.bitDepth), - channels(img.channels), width(img.width), height(img.height), size(img.size), data(img.data) + : BaseObj((BaseObj&&)img), hashId(img.hashId), id((Str_8&&)img.id), byteDepth(img.byteDepth), + channels(img.channels), resolution(img.resolution), size(img.size), data(img.data) { - img.bitDepth = 0; + img.byteDepth = 0; img.channels = 0; - img.width = 0; - img.height = 0; + img.resolution = {}; img.size = 0; img.data = nullptr; } Img::Img(const Img& img) - : BaseObj(img), hashId(img.hashId), id(img.id), bitDepth(img.bitDepth), channels(img.channels), width(img.width), - height(img.height), size(img.size), data(new Byte[img.size]) + : BaseObj(img), hashId(img.hashId), id(img.id), byteDepth(img.byteDepth), channels(img.channels), + resolution(img.resolution), size(img.size), data(new Byte[img.size]) { Util::Copy(data, img.data, img.size); } @@ -101,18 +100,16 @@ namespace ehs BaseObj::operator=((BaseObj&&)img); - bitDepth = img.bitDepth; + byteDepth = img.byteDepth; channels = img.channels; - width = img.width; - height = img.height; + resolution = img.resolution; size = img.size; delete[] data; data = img.data; - img.bitDepth = 0; + img.byteDepth = 0; img.channels = 0; - img.width = 0; - img.height = 0; + img.resolution = {}; img.size = 0; img.data = nullptr; @@ -126,10 +123,9 @@ namespace ehs BaseObj::operator=(img); - bitDepth = img.bitDepth; + byteDepth = img.byteDepth; channels = img.channels; - width = img.width; - height = img.height; + resolution = img.resolution; size = img.size; delete[] data; data = new Byte[img.size]; @@ -150,10 +146,9 @@ namespace ehs void Img::Release() { - bitDepth = 0; + byteDepth = 0; channels = 0; - width = 0; - height = 0; + resolution = {}; size = 0; delete[] data; data = nullptr; @@ -175,70 +170,70 @@ namespace ehs return id; } - UInt_8 Img::BitDepth() const + UInt_8 Img::GetByteDepth() const { - return bitDepth; + return byteDepth; } - UInt_8 Img::Channels() const + UInt_8 Img::GetBitDepth() const + { + return byteDepth * 8; + } + + UInt_8 Img::GetChannels() const { return channels; } - UInt_64 Img::Width() const + Vec2_u64 Img::GetResolution() const { - return width; + return resolution; } - UInt_64 Img::Height() const - { - return height; - } - - UInt_64 Img::Size() const + UInt_64 Img::GetSize() const { return size; } void Img::SetPixel(const UInt_64 index, const Byte* const pixel) { - UInt_64 rIndex = index * (bitDepth / 8) * channels; + UInt_64 rIndex = index * byteDepth * channels; - for (UInt_64 i = 0; i < bitDepth / 8 * channels; ++i) + for (UInt_64 i = 0; i < byteDepth * channels; ++i) data[rIndex + i] = pixel[i]; } void Img::GetPixel(const UInt_64 index, Byte* const pixel) const { - UInt_64 rIndex = index * (bitDepth / 8) * channels; + UInt_64 rIndex = index * byteDepth * channels; - for (UInt_64 i = 0; i < bitDepth / 8 * channels; ++i) + for (UInt_64 i = 0; i < byteDepth * channels; ++i) pixel[i] = data[rIndex + i]; } void Img::SetPixel(const UInt_64 x, const UInt_64 y, const Byte* const pixel) { - UInt_64 rIndex = (y * width * (bitDepth / 8) * channels) + (x * (bitDepth / 8) * channels); + UInt_64 rIndex = (y * resolution.x * byteDepth * channels) + (x * byteDepth * channels); - for (UInt_64 i = 0; i < bitDepth / 8 * channels; ++i) + for (UInt_64 i = 0; i < byteDepth * channels; ++i) data[rIndex + i] = pixel[i]; } void Img::GetPixel(const UInt_64 x, const UInt_64 y, Byte* const pixel) const { - UInt_64 rIndex = (y * width * (bitDepth / 8) * channels) + (x * (bitDepth / 8) * channels); + UInt_64 rIndex = (y * resolution.x * byteDepth * channels) + (x * byteDepth * channels); - for (UInt_64 i = 0; i < bitDepth / 8 * channels; ++i) + for (UInt_64 i = 0; i < byteDepth * channels; ++i) pixel[i] = data[rIndex + i]; } - void Img::Resize(const Resampling method, const UInt_64 newWidth, const UInt_64 newHeight) + void Img::Resize(const Resampling method, const Vec2_u64& newResolution) { switch (method) { case Resampling::NEAREST_NEIGHBOR: { - NearestNeighbor(newWidth, newHeight); + NearestNeighbor(newResolution); return; } default: @@ -246,12 +241,12 @@ namespace ehs } } - Img Img::GetResized(const Resampling method, const UInt_64 newWidth, const UInt_64 newHeight) const + Img Img::GetResized(const Resampling method, const Vec2_u64& newResolution) const { switch (method) { case Resampling::NEAREST_NEIGHBOR: - return GetNearestNeighbor(newWidth, newHeight); + return GetNearestNeighbor(newResolution); default: return {}; } @@ -263,7 +258,7 @@ namespace ehs { case 3: { - size = width * height * (bitDepth / 8) * 4; + size = resolution.x * resolution.y * byteDepth * 4; Byte* result = new Byte[size]; RGB_To_RGBA(size, result); channels = 4; @@ -273,7 +268,7 @@ namespace ehs } case 2: { - size = width * height * (bitDepth / 8) * 4; + size = resolution.x * resolution.y * byteDepth * 4; Byte* result = new Byte[size]; MonoA_To_RGBA(size, result); channels = 4; @@ -283,7 +278,7 @@ namespace ehs } case 1: { - size = width * height * (bitDepth / 8) * 4; + size = resolution.x * resolution.y * byteDepth * 4; Byte* result = new Byte[size]; Mono_To_RGBA(size, result); channels = 4; @@ -308,20 +303,20 @@ namespace ehs } case 3: { - Img result(id, bitDepth, 4, width, height); - RGB_To_RGBA(result.Size(), result); + Img result(id, byteDepth, 4, resolution); + RGB_To_RGBA(result.GetSize(), result); return result; } case 2: { - Img result(id, bitDepth, 4, width, height); - MonoA_To_RGBA(result.Size(), result); + Img result(id, byteDepth, 4, resolution); + MonoA_To_RGBA(result.GetSize(), result); return result; } case 1: { - Img result(id, bitDepth, 4, width, height); - Mono_To_RGBA(result.Size(), result); + Img result(id, byteDepth, 4, resolution); + Mono_To_RGBA(result.GetSize(), result); return result; } default: @@ -337,7 +332,7 @@ namespace ehs { case 4: { - size = width * height * (bitDepth / 8) * 3; + size = resolution.x * resolution.y * byteDepth * 3; Byte* result = new Byte[size]; RGBA_To_RGB(size, result); channels = 3; @@ -347,7 +342,7 @@ namespace ehs } case 2: { - size = width * height * (bitDepth / 8) * 3; + size = resolution.x * resolution.y * byteDepth * 3; Byte* result = new Byte[size]; MonoA_To_RGB(size, result); channels = 3; @@ -357,7 +352,7 @@ namespace ehs } case 1: { - size = width * height * (bitDepth / 8) * 3; + size = resolution.x * resolution.y * byteDepth * 3; Byte* result = new Byte[size]; Mono_To_RGB(size, result); channels = 3; @@ -378,8 +373,8 @@ namespace ehs { case 4: { - Img result(id, bitDepth, 3, width, height); - RGBA_To_RGB(result.Size(), result); + Img result(id, byteDepth, 3, resolution); + RGBA_To_RGB(result.GetSize(), result); return result; } case 3: @@ -388,14 +383,14 @@ namespace ehs } case 2: { - Img result(id, bitDepth, 3, width, height); - MonoA_To_RGB(result.Size(), result); + Img result(id, byteDepth, 3, resolution); + MonoA_To_RGB(result.GetSize(), result); return result; } case 1: { - Img result(id, bitDepth, 3, width, height); - Mono_To_RGB(result.Size(), result); + Img result(id, byteDepth, 3, resolution); + Mono_To_RGB(result.GetSize(), result); return result; } default: @@ -411,7 +406,7 @@ namespace ehs { case 4: { - size = width * height * (bitDepth / 8) * 2; + size = resolution.x * resolution.y * byteDepth * 2; Byte* result = new Byte[size]; RGBA_To_MonoA(size, result); channels = 2; @@ -421,7 +416,7 @@ namespace ehs } case 3: { - size = width * height * (bitDepth / 8) * 2; + size = resolution.x * resolution.y * byteDepth * 2; Byte* result = new Byte[size]; RGB_To_MonoA(size, result); channels = 2; @@ -431,7 +426,7 @@ namespace ehs } case 1: { - size = width * height * (bitDepth / 8) * 2; + size = resolution.x * resolution.y * byteDepth * 2; Byte* result = new Byte[size]; Mono_To_MonoA(size, result); channels = 2; @@ -452,14 +447,14 @@ namespace ehs { case 4: { - Img result(id, bitDepth, 2, width, height); - RGBA_To_MonoA(result.Size(), result); + Img result(id, byteDepth, 2, resolution); + RGBA_To_MonoA(result.GetSize(), result); return result; } case 3: { - Img result(id, bitDepth, 2, width, height); - RGB_To_MonoA(result.Size(), result); + Img result(id, byteDepth, 2, resolution); + RGB_To_MonoA(result.GetSize(), result); return result; } case 2: @@ -468,8 +463,8 @@ namespace ehs } case 1: { - Img result(id, bitDepth, 2, width, height); - Mono_To_MonoA(result.Size(), result); + Img result(id, byteDepth, 2, resolution); + Mono_To_MonoA(result.GetSize(), result); return result; } default: @@ -485,7 +480,7 @@ namespace ehs { case 4: { - size = width * height * (bitDepth / 8); + size = resolution.x * resolution.y * byteDepth; Byte* result = new Byte[size]; RGBA_To_Mono(size, result); channels = 1; @@ -495,7 +490,7 @@ namespace ehs } case 3: { - size = width * height * (bitDepth / 8); + size = resolution.x * resolution.y * byteDepth; Byte* result = new Byte[size]; RGB_To_Mono(size, result); channels = 1; @@ -505,7 +500,7 @@ namespace ehs } case 2: { - size = width * height * (bitDepth / 8); + size = resolution.x * resolution.y * byteDepth; Byte* result = new Byte[size]; MonoA_To_Mono(size, result); channels = 1; @@ -526,20 +521,20 @@ namespace ehs { case 4: { - Img result(id, bitDepth, 1, width, height); - RGBA_To_Mono(result.Size(), result); + Img result(id, byteDepth, 1, resolution); + RGBA_To_Mono(result.GetSize(), result); return result; } case 3: { - Img result(id, bitDepth, 1, width, height); - RGB_To_Mono(result.Size(), result); + Img result(id, byteDepth, 1, resolution); + RGB_To_Mono(result.GetSize(), result); return result; } case 2: { - Img result(id, bitDepth, 1, width, height); - MonoA_To_Mono(result.Size(), result); + Img result(id, byteDepth, 1, resolution); + MonoA_To_Mono(result.GetSize(), result); return result; } case 1: @@ -555,34 +550,34 @@ namespace ehs void Img::To32() { - switch (bitDepth) + switch (byteDepth) { - case 24: + case 3: { - size = width * height * 4 * channels; + size = resolution.x * resolution.y * 4 * channels; Byte* result = new Byte[size]; BD24_to_BD32(size, result); - bitDepth = 32; + byteDepth = 4; delete[] data; data = result; break; } - case 16: + case 2: { - size = width * height * 4 * channels; + size = resolution.x * resolution.y * 4 * channels; Byte* result = new Byte[size]; BD16_to_BD32(size, result); - bitDepth = 32; + byteDepth = 4; delete[] data; data = result; break; } - case 8: + case 1: { - size = width * height * 4 * channels; + size = resolution.x * resolution.y * 4 * channels; Byte* result = new Byte[size]; BD8_to_BD32(size, result); - bitDepth = 32; + byteDepth = 4; delete[] data; data = result; break; @@ -596,28 +591,28 @@ namespace ehs Img Img::GetAs32() const { - switch (bitDepth) + switch (byteDepth) { - case 32: + case 4: { return {*this}; } - case 24: + case 3: { - Img result(id, 32, channels, width, height); - BD24_to_BD32(result.Size(), result); + Img result(id, 4, channels, resolution); + BD24_to_BD32(result.GetSize(), result); return result; } - case 16: + case 2: { - Img result(id, 32, channels, width, height); - BD16_to_BD32(result.Size(), result); + Img result(id, 4, channels, resolution); + BD16_to_BD32(result.GetSize(), result); return result; } - case 8: + case 1: { - Img result(id, 32, channels, width, height); - BD8_to_BD32(result.Size(), result); + Img result(id, 4, channels, resolution); + BD8_to_BD32(result.GetSize(), result); return result; } default: @@ -629,34 +624,34 @@ namespace ehs void Img::To24() { - switch (bitDepth) + switch (byteDepth) { - case 32: + case 4: { - size = width * height * 3 * channels; + size = resolution.x * resolution.y * 3 * channels; Byte* result = new Byte[size]; BD32_to_BD24(size, result); - bitDepth = 24; + byteDepth = 3; delete[] data; data = result; break; } - case 16: + case 2: { - size = width * height * 3 * channels; + size = resolution.x * resolution.y * 3 * channels; Byte* result = new Byte[size]; BD16_to_BD24(size, result); - bitDepth = 24; + byteDepth = 3; delete[] data; data = result; break; } - case 8: + case 1: { - size = width * height * 3 * channels; + size = resolution.x * resolution.y * 3 * channels; Byte* result = new Byte[size]; BD8_to_BD24(size, result); - bitDepth = 24; + byteDepth = 3; delete[] data; data = result; break; @@ -670,28 +665,28 @@ namespace ehs Img Img::GetAs24() const { - switch (bitDepth) + switch (byteDepth) { - case 32: + case 4: { - Img result(id, 24, channels, width, height); - BD32_to_BD24(result.Size(), result); + Img result(id, 3, channels, resolution); + BD32_to_BD24(result.GetSize(), result); return result; } - case 24: + case 3: { return {*this}; } - case 16: + case 2: { - Img result(id, 24, channels, width, height); - BD16_to_BD24(result.Size(), result); + Img result(id, 3, channels, resolution); + BD16_to_BD24(result.GetSize(), result); return result; } - case 8: + case 1: { - Img result(id, 24, channels, width, height); - BD8_to_BD24(result.Size(), result); + Img result(id, 3, channels, resolution); + BD8_to_BD24(result.GetSize(), result); return result; } default: @@ -703,34 +698,34 @@ namespace ehs void Img::To16() { - switch (bitDepth) + switch (byteDepth) { - case 32: + case 4: { - size = width * height * 2 * channels; + size = resolution.x * resolution.y * 2 * channels; Byte* result = new Byte[size]; BD32_to_BD16(size, result); - bitDepth = 16; + byteDepth = 2; delete[] data; data = result; break; } - case 24: + case 3: { - size = width * height * 2 * channels; + size = resolution.x * resolution.y * 2 * channels; Byte* result = new Byte[size]; BD24_to_BD16(size, result); - bitDepth = 16; + byteDepth = 2; delete[] data; data = result; break; } - case 8: + case 1: { - size = width * height * 2 * channels; + size = resolution.x * resolution.y * 2 * channels; Byte* result = new Byte[size]; BD8_to_BD16(size, result); - bitDepth = 16; + byteDepth = 2; delete[] data; data = result; break; @@ -744,28 +739,28 @@ namespace ehs Img Img::GetAs16() const { - switch (bitDepth) + switch (byteDepth) { - case 32: + case 4: { - Img result(id, 16, channels, width, height); - BD32_to_BD16(result.Size(), result); + Img result(id, 2, channels, resolution); + BD32_to_BD16(result.GetSize(), result); return result; } - case 24: + case 3: { - Img result(id, 16, channels, width, height); - BD24_to_BD16(result.Size(), result); + Img result(id, 2, channels, resolution); + BD24_to_BD16(result.GetSize(), result); return result; } - case 16: + case 2: { return {*this}; } - case 8: + case 1: { - Img result(id, 16, channels, width, height); - BD8_to_BD16(result.Size(), result); + Img result(id, 2, channels, resolution); + BD8_to_BD16(result.GetSize(), result); return result; } default: @@ -777,34 +772,34 @@ namespace ehs void Img::To8() { - switch (bitDepth) + switch (byteDepth) { - case 32: + case 4: { - size = width * height * channels; + size = resolution.x * resolution.y * channels; Byte* result = new Byte[size]; BD32_to_BD8(size, result); - bitDepth = 8; + byteDepth = 1; delete[] data; data = result; break; } - case 24: + case 3: { - size = width * height * channels; + size = resolution.x * resolution.y * channels; Byte* result = new Byte[size]; BD24_to_BD8(size, result); - bitDepth = 8; + byteDepth = 1; delete[] data; data = result; break; } - case 16: + case 2: { - size = width * height * channels; + size = resolution.x * resolution.y * channels; Byte* result = new Byte[size]; BD16_to_BD8(size, result); - bitDepth = 8; + byteDepth = 1; delete[] data; data = result; break; @@ -818,27 +813,27 @@ namespace ehs Img Img::GetAs8() const { - switch (bitDepth) + switch (byteDepth) { - case 32: + case 4: { - Img result(id, 8, channels, width, height); - BD32_to_BD8(result.Size(), result); + Img result(id, 1, channels, resolution); + BD32_to_BD8(result.GetSize(), result); return result; } - case 24: + case 3: { - Img result(id, 8, channels, width, height); - BD24_to_BD8(result.Size(), result); + Img result(id, 1, channels, resolution); + BD24_to_BD8(result.GetSize(), result); return result; } - case 16: + case 2: { - Img result(id, 8, channels, width, height); - BD16_to_BD8(result.Size(), result); + Img result(id, 1, channels, resolution); + BD16_to_BD8(result.GetSize(), result); return result; } - case 8: + case 1: { return {*this}; } @@ -851,12 +846,12 @@ namespace ehs bool Img::IsValid() const { - return width && height; + return size; } bool Img::ToFile(const Str_8& filePath) const { - Str_8 ext = File::ProcessExt_8(filePath); + Str_8 ext = File::ParseExt_8(filePath); const ImgCodec* codec = GetCodec(ext); if (!codec) @@ -945,166 +940,155 @@ namespace ehs return result; } - Img Img::GetNearestNeighbor(const UInt_64 newWidth, const UInt_64 newHeight) const + Img Img::GetNearestNeighbor(const Vec2_u64& newResolution) const { - UInt_8 bytes = bitDepth / 8; + Img result(id, byteDepth, channels, newResolution); - Img result(id, bitDepth, channels, newWidth, newHeight); + Vec2_d ratio = { + (double)resolution.x / (double)newResolution.x, + (double)resolution.y / (double)newResolution.x + }; - double xRatio = (double)width / (double)newWidth; - double yRatio = (double)height / (double)newWidth; - double px; - double py; + Vec2_d pixel; - for(UInt_64 y = 0; y < newHeight; ++y) + for(UInt_64 y = 0; y < newResolution.y; ++y) { - for (UInt_64 x = 0; x < newWidth; ++x) + for (UInt_64 x = 0; x < newResolution.x; ++x) { - px = Math::Floor((double)x * xRatio); - py = Math::Floor((double)y * yRatio); + pixel = { + Math::Floor((double)x * ratio.x), + Math::Floor((double)y * ratio.y) + }; - for (UInt_64 b = 0; b < bytes * channels; ++b) - result[y * newWidth * bytes * channels + x * bytes * channels + b] = data[(UInt_64)py * width * bytes * channels + (UInt_64)px * bytes * channels + b]; + for (UInt_64 b = 0; b < byteDepth * channels; ++b) + result[y * newResolution.x * byteDepth * channels + x * byteDepth * channels + b] = data[(UInt_64)pixel.y * resolution.x * byteDepth * channels + (UInt_64)pixel.x * byteDepth * channels + b]; } } return result; } - void Img::NearestNeighbor(const UInt_64 newWidth, const UInt_64 newHeight) + void Img::NearestNeighbor(const Vec2_u64& newResolution) { - UInt_8 bytes = bitDepth / 8; + Byte* result = new Byte[newResolution.x * byteDepth * channels * newResolution.y]; - Byte* result = new Byte[newWidth * bytes * channels * newHeight]; + Vec2_d ratio = { + (double)resolution.x / (double)newResolution.x, + (double)resolution.y / (double)newResolution.x + }; - double xRatio = (double)width / (double)newWidth; - double yRatio = (double)height / (double)newWidth; - double px; - double py; + Vec2_d pixel; - for(UInt_64 y = 0; y < newHeight; ++y) + for(UInt_64 y = 0; y < newResolution.y; ++y) { - for (UInt_64 x = 0; x < newWidth; ++x) + for (UInt_64 x = 0; x < newResolution.x; ++x) { - px = Math::Floor((double)x * xRatio); - py = Math::Floor((double)y * yRatio); + pixel = { + Math::Floor((double)x * ratio.x), + Math::Floor((double)y * ratio.y) + }; - for (UInt_64 b = 0; b < bytes * channels; ++b) - result[y * newWidth * bytes * channels + x * bytes * channels + b] = data[(UInt_64)py * width * bytes * channels + (UInt_64)px * bytes * channels + b]; + for (UInt_64 b = 0; b < byteDepth * channels; ++b) + result[y * newResolution.x * byteDepth * channels + x * byteDepth * channels + b] = data[(UInt_64)pixel.y * resolution.x * byteDepth * channels + (UInt_64)pixel.x * byteDepth * channels + b]; } } delete[] data; data = result; - width = newWidth; - height = newHeight; + resolution = newResolution; } void Img::RGB_To_RGBA(const UInt_64 newSize, Byte* buffer) const { - UInt_8 bytes = bitDepth / 8; - - for (UInt_64 i = 0, n = 0; i < newSize; i += bytes * 4, n += bytes * channels) + for (UInt_64 i = 0, n = 0; i < newSize; i += byteDepth * 4, n += byteDepth * channels) { - for (UInt_64 b = 0; b < bytes * 3; ++b) + for (UInt_64 b = 0; b < byteDepth * 3; ++b) buffer[i + b] = data[n + b]; - if (bytes == 1) - buffer[i + bytes * 3] = EHS_UINT_8_MAX; - else if (bytes == 2) - *(UInt_16*)&buffer[i + bytes * 3] = EHS_UINT_16_MAX; - else if (bytes == 3) + if (byteDepth == 1) + buffer[i + byteDepth * 3] = EHS_UINT_8_MAX; + else if (byteDepth == 2) + *(UInt_16*)&buffer[i + byteDepth * 3] = EHS_UINT_16_MAX; + else if (byteDepth == 3) { UInt_32 value = EHS_UINT_24_MAX; - for (UInt_64 b = 0; b < bytes; ++b) - buffer[i + bytes * 3 + b] = ((Byte*)&value)[b]; + for (UInt_64 b = 0; b < byteDepth; ++b) + buffer[i + byteDepth * 3 + b] = ((Byte*)&value)[b]; } - else if (bytes == 4) - *(UInt_32*)&buffer[i + bytes * 3] = EHS_UINT_32_MAX; + else if (byteDepth == 4) + *(UInt_32*)&buffer[i + byteDepth * 3] = EHS_UINT_32_MAX; } } void Img::MonoA_To_RGBA(const UInt_64 newSize, Byte* buffer) const { - UInt_8 bytes = bitDepth / 8; - - for (UInt_64 i = 0, n = 0; i < newSize; i += bytes * 4, n += bytes * channels) + for (UInt_64 i = 0, n = 0; i < newSize; i += byteDepth * 4, n += byteDepth * channels) { - for (UInt_64 b = 0; b < bytes * 4; ++b) - buffer[i + b] = data[n + b % bytes]; + for (UInt_64 b = 0; b < byteDepth * 4; ++b) + buffer[i + b] = data[n + b % byteDepth]; - if (bytes == 1) - buffer[i + bytes * 3] = data[n + bytes]; - else if (bytes == 2) - *(UInt_16*) &buffer[i + bytes * 3] = *(UInt_16*) &data[n + bytes]; - else if (bytes == 3) + if (byteDepth == 1) + buffer[i + byteDepth * 3] = data[n + byteDepth]; + else if (byteDepth == 2) + *(UInt_16*) &buffer[i + byteDepth * 3] = *(UInt_16*) &data[n + byteDepth]; + else if (byteDepth == 3) { - for (UInt_64 b = 0; b < bytes; ++b) - buffer[i + bytes * 3 + b] = data[n + bytes + b]; + for (UInt_64 b = 0; b < byteDepth; ++b) + buffer[i + byteDepth * 3 + b] = data[n + byteDepth + b]; } - else if (bytes == 4) - *(UInt_32*) &buffer[i + bytes * 3] = *(UInt_32*) &data[n + bytes]; + else if (byteDepth == 4) + *(UInt_32*) &buffer[i + byteDepth * 3] = *(UInt_32*) &data[n + byteDepth]; } } void Img::Mono_To_RGBA(const UInt_64 newSize, Byte* buffer) const { - UInt_8 bytes = bitDepth / 8; - - for (UInt_64 i = 0, n = 0; i < newSize; i += bytes * 4, n += bytes * channels) + for (UInt_64 i = 0, n = 0; i < newSize; i += byteDepth * 4, n += byteDepth * channels) { - for (UInt_64 b = 0; b < bytes * 4; ++b) - buffer[i + b] = data[n + b % bytes]; + for (UInt_64 b = 0; b < byteDepth * 4; ++b) + buffer[i + b] = data[n + b % byteDepth]; - if (bytes == 1) - buffer[i + bytes * 3] = EHS_UINT_8_MAX; - else if (bytes == 2) - *(UInt_16*)&buffer[i + bytes * 3] = EHS_UINT_16_MAX; - else if (bytes == 3) + if (byteDepth == 1) + buffer[i + byteDepth * 3] = EHS_UINT_8_MAX; + else if (byteDepth == 2) + *(UInt_16*)&buffer[i + byteDepth * 3] = EHS_UINT_16_MAX; + else if (byteDepth == 3) { UInt_32 value = EHS_UINT_24_MAX; - for (UInt_64 b = 0; b < bytes; ++b) - buffer[i + bytes * 3 + b] = ((Byte*)&value)[b]; + for (UInt_64 b = 0; b < byteDepth; ++b) + buffer[i + byteDepth * 3 + b] = ((Byte*)&value)[b]; } - else if (bytes == 4) - *(UInt_32*) &buffer[i + bytes * 3] = EHS_UINT_32_MAX; + else if (byteDepth == 4) + *(UInt_32*) &buffer[i + byteDepth * 3] = EHS_UINT_32_MAX; } } void Img::RGBA_To_RGB(const UInt_64 newSize, Byte* buffer) const { - UInt_8 bytes = bitDepth / 8; - - for (UInt_64 i = 0, n = 0; i < newSize; i += bytes * 3, n += bytes * channels) - for (UInt_64 b = 0; b < bytes * 3; ++b) + for (UInt_64 i = 0, n = 0; i < newSize; i += byteDepth * 3, n += byteDepth * channels) + for (UInt_64 b = 0; b < byteDepth * 3; ++b) buffer[i + b] = data[n + b]; } void Img::MonoA_To_RGB(const UInt_64 newSize, Byte* buffer) const { - UInt_8 bytes = bitDepth / 8; - - for (UInt_64 i = 0, n = 0; i < newSize; i += bytes * 3, n += bytes * channels) - for (UInt_64 b = 0; b < bytes * 3; ++b) - buffer[i + b] = data[n + b % bytes]; + for (UInt_64 i = 0, n = 0; i < newSize; i += byteDepth * 3, n += byteDepth * channels) + for (UInt_64 b = 0; b < byteDepth * 3; ++b) + buffer[i + b] = data[n + b % byteDepth]; } void Img::Mono_To_RGB(const UInt_64 newSize, Byte* buffer) const { - UInt_8 bytes = bitDepth / 8; - - for (UInt_64 i = 0, n = 0; i < newSize; i += bytes * 3, n += bytes * channels) - for (UInt_64 b = 0; b < bytes * 3; ++b) - buffer[i + b] = data[n + b % bytes]; + for (UInt_64 i = 0, n = 0; i < newSize; i += byteDepth * 3, n += byteDepth * channels) + for (UInt_64 b = 0; b < byteDepth * 3; ++b) + buffer[i + b] = data[n + b % byteDepth]; } void Img::RGBA_To_MonoA(const UInt_64 newSize, Byte* buffer) const { - UInt_8 bytes = bitDepth / 8; - - for (UInt_64 i = 0, n = 0; i < newSize; i += bytes * 2, n += bytes * channels) + for (UInt_64 i = 0, n = 0; i < newSize; i += byteDepth * 2, n += byteDepth * channels) { - if (bytes == 1) + if (byteDepth == 1) { UInt_16 average = 0; @@ -1112,23 +1096,23 @@ namespace ehs average += data[n + b]; buffer[i] = average / 4; - buffer[i + bytes] = data[n + 3]; + buffer[i + byteDepth] = data[n + 3]; } - else if (bytes == 2) + else if (byteDepth == 2) { UInt_32 average = 0; - for (UInt_64 b = 0; b < bytes * 3; b += bytes) + for (UInt_64 b = 0; b < byteDepth * 3; b += byteDepth) average += *(UInt_16*)&data[n + b]; *(UInt_16*)&buffer[i] = average / 4; - *(UInt_16*)&buffer[i + bytes] = *(UInt_16*)&data[n + bytes * 3]; + *(UInt_16*)&buffer[i + byteDepth] = *(UInt_16*)&data[n + byteDepth * 3]; } - else if (bytes == 3) + else if (byteDepth == 3) { UInt_64 average = 0; - for (UInt_64 b = 0; b < bytes * 3; b += bytes) + for (UInt_64 b = 0; b < byteDepth * 3; b += byteDepth) { UInt_32 num = 0; num |= data[n + b]; @@ -1144,30 +1128,28 @@ namespace ehs buffer[i + 1] = ((Byte*)&average)[1]; buffer[i + 2] = ((Byte*)&average)[2]; - buffer[i + bytes] = data[n + bytes * 3]; - buffer[i + bytes + 1] = data[n + bytes * 3 + 1]; - buffer[i + bytes + 2] = data[n + bytes * 3 + 2]; + buffer[i + byteDepth] = data[n + byteDepth * 3]; + buffer[i + byteDepth + 1] = data[n + byteDepth * 3 + 1]; + buffer[i + byteDepth + 2] = data[n + byteDepth * 3 + 2]; } - else if (bytes == 4) + else if (byteDepth == 4) { UInt_64 average = 0; - for (UInt_64 b = 0; b < bytes * 3; b += bytes) + for (UInt_64 b = 0; b < byteDepth * 3; b += byteDepth) average += *(UInt_32*)&data[n + b]; *(UInt_32*)&buffer[i] = average / 4; - *(UInt_32*)&buffer[i + bytes] = *(UInt_32*)&data[n + bytes * 3]; + *(UInt_32*)&buffer[i + byteDepth] = *(UInt_32*)&data[n + byteDepth * 3]; } } } void Img::RGB_To_MonoA(const UInt_64 newSize, Byte* buffer) const { - UInt_8 bytes = bitDepth / 8; - - for (UInt_64 i = 0, n = 0; i < newSize; i += bytes * 2, n += bytes * channels) + for (UInt_64 i = 0, n = 0; i < newSize; i += byteDepth * 2, n += byteDepth * channels) { - if (bytes == 1) + if (byteDepth == 1) { UInt_16 average = 0; @@ -1175,23 +1157,23 @@ namespace ehs average += data[n + b]; buffer[i] = average / 4; - buffer[i + bytes] = EHS_UINT_8_MAX; + buffer[i + byteDepth] = EHS_UINT_8_MAX; } - else if (bytes == 2) + else if (byteDepth == 2) { UInt_32 average = 0; - for (UInt_64 b = 0; b < bytes * 3; b += bytes) + for (UInt_64 b = 0; b < byteDepth * 3; b += byteDepth) average += *(UInt_16*)&data[n + b]; *(UInt_16*)&buffer[i] = average / 4; - *(UInt_16*)&buffer[i + bytes] = EHS_UINT_16_MAX; + *(UInt_16*)&buffer[i + byteDepth] = EHS_UINT_16_MAX; } - else if (bytes == 3) + else if (byteDepth == 3) { UInt_64 average = 0; - for (UInt_64 b = 0; b < bytes * 3; b += bytes) + for (UInt_64 b = 0; b < byteDepth * 3; b += byteDepth) { UInt_32 num = 0; num |= data[n + b]; @@ -1209,40 +1191,38 @@ namespace ehs UInt_32 tmp = EHS_UINT_24_MAX; - buffer[i + bytes] = ((Byte*)&tmp)[0]; - buffer[i + bytes + 1] = ((Byte*)&tmp)[1]; - buffer[i + bytes + 2] = ((Byte*)&tmp)[2]; + buffer[i + byteDepth] = ((Byte*)&tmp)[0]; + buffer[i + byteDepth + 1] = ((Byte*)&tmp)[1]; + buffer[i + byteDepth + 2] = ((Byte*)&tmp)[2]; } - else if (bytes == 4) + else if (byteDepth == 4) { UInt_64 average = 0; - for (UInt_64 b = 0; b < bytes * 3; b += bytes) + for (UInt_64 b = 0; b < byteDepth * 3; b += byteDepth) average += *(UInt_32*)&data[n + b]; *(UInt_32*)&buffer[i] = average / 4; - *(UInt_32*)&buffer[i + bytes] = EHS_UINT_32_MAX; + *(UInt_32*)&buffer[i + byteDepth] = EHS_UINT_32_MAX; } } } void Img::Mono_To_MonoA(const UInt_64 newSize, Byte* buffer) const { - UInt_8 bytes = bitDepth / 8; - - for (UInt_64 i = 0, n = 0; i < newSize; i += bytes * 2, n += bytes * channels) + for (UInt_64 i = 0, n = 0; i < newSize; i += byteDepth * 2, n += byteDepth * channels) { - if (bytes == 1) + if (byteDepth == 1) { buffer[i] = data[n]; - buffer[i + bytes] = EHS_UINT_8_MAX; + buffer[i + byteDepth] = EHS_UINT_8_MAX; } - else if (bytes == 2) + else if (byteDepth == 2) { *(UInt_16*)&buffer[i] = *(UInt_16*)&data[n]; - *(UInt_16*)&buffer[i + bytes] = EHS_UINT_16_MAX; + *(UInt_16*)&buffer[i + byteDepth] = EHS_UINT_16_MAX; } - else if (bytes == 3) + else if (byteDepth == 3) { buffer[i] = data[n]; buffer[i + 1] = data[n + 1]; @@ -1250,25 +1230,23 @@ namespace ehs UInt_32 tmp = EHS_UINT_24_MAX; - buffer[i + bytes] = ((Byte*)&tmp)[0]; - buffer[i + bytes + 1] = ((Byte*)&tmp)[1]; - buffer[i + bytes + 2] = ((Byte*)&tmp)[2]; + buffer[i + byteDepth] = ((Byte*)&tmp)[0]; + buffer[i + byteDepth + 1] = ((Byte*)&tmp)[1]; + buffer[i + byteDepth + 2] = ((Byte*)&tmp)[2]; } - else if (bytes == 4) + else if (byteDepth == 4) { *(UInt_32*)&buffer[i] = *(UInt_32*)&data[n]; - *(UInt_32*)&buffer[i + bytes] = EHS_UINT_32_MAX; + *(UInt_32*)&buffer[i + byteDepth] = EHS_UINT_32_MAX; } } } void Img::RGBA_To_Mono(const UInt_64 newSize, Byte* buffer) const { - UInt_8 bytes = bitDepth / 8; - - for (UInt_64 i = 0, n = 0; i < newSize; i += bytes, n += bytes * channels) + for (UInt_64 i = 0, n = 0; i < newSize; i += byteDepth, n += byteDepth * channels) { - if (bytes == 1) + if (byteDepth == 1) { UInt_16 average = 0; @@ -1277,20 +1255,20 @@ namespace ehs buffer[i] = average / 4; } - else if (bytes == 2) + else if (byteDepth == 2) { UInt_32 average = 0; - for (UInt_64 b = 0; b < bytes * 3; b += bytes) + for (UInt_64 b = 0; b < byteDepth * 3; b += byteDepth) average += *(UInt_16*)&data[n + b]; *(UInt_16*)&buffer[i] = average / 4; } - else if (bytes == 3) + else if (byteDepth == 3) { UInt_64 average = 0; - for (UInt_64 b = 0; b < bytes * 3; b += bytes) + for (UInt_64 b = 0; b < byteDepth * 3; b += byteDepth) { UInt_32 num = 0; num |= data[n + b]; @@ -1306,11 +1284,11 @@ namespace ehs buffer[i + 1] = ((Byte*)&average)[1]; buffer[i + 2] = ((Byte*)&average)[2]; } - else if (bytes == 4) + else if (byteDepth == 4) { UInt_64 average = 0; - for (UInt_64 b = 0; b < bytes * 3; b += bytes) + for (UInt_64 b = 0; b < byteDepth * 3; b += byteDepth) average += *(UInt_32*)&data[n + b]; *(UInt_32*)&buffer[i] = average / 4; @@ -1320,11 +1298,9 @@ namespace ehs void Img::RGB_To_Mono(const UInt_64 newSize, Byte* buffer) const { - UInt_8 bytes = bitDepth / 8; - - for (UInt_64 i = 0, n = 0; i < newSize; i += bytes, n += bytes * channels) + for (UInt_64 i = 0, n = 0; i < newSize; i += byteDepth, n += byteDepth * channels) { - if (bytes == 1) + if (byteDepth == 1) { UInt_16 average = 0; @@ -1333,20 +1309,20 @@ namespace ehs buffer[i] = average / 4; } - else if (bytes == 2) + else if (byteDepth == 2) { UInt_32 average = 0; - for (UInt_64 b = 0; b < bytes * 3; b += bytes) + for (UInt_64 b = 0; b < byteDepth * 3; b += byteDepth) average += *(UInt_16*)&data[n + b]; *(UInt_16*)&buffer[i] = average / 4; } - else if (bytes == 3) + else if (byteDepth == 3) { UInt_64 average = 0; - for (UInt_64 b = 0; b < bytes * 3; b += bytes) + for (UInt_64 b = 0; b < byteDepth * 3; b += byteDepth) { UInt_32 num = 0; num |= data[n + b]; @@ -1362,11 +1338,11 @@ namespace ehs buffer[i + 1] = ((Byte*)&average)[1]; buffer[i + 2] = ((Byte*)&average)[2]; } - else if (bytes == 4) + else if (byteDepth == 4) { UInt_64 average = 0; - for (UInt_64 b = 0; b < bytes * 3; b += bytes) + for (UInt_64 b = 0; b < byteDepth * 3; b += byteDepth) average += *(UInt_32*)&data[n + b]; *(UInt_32*)&buffer[i] = average / 4; @@ -1376,25 +1352,23 @@ namespace ehs void Img::MonoA_To_Mono(const UInt_64 newSize, Byte* buffer) const { - UInt_8 bytes = bitDepth / 8; - - for (UInt_64 i = 0, n = 0; i < newSize; i += bytes, n += bytes * channels) + for (UInt_64 i = 0, n = 0; i < newSize; i += byteDepth, n += byteDepth * channels) { - if (bytes == 1) + if (byteDepth == 1) { buffer[i] = data[n]; } - else if (bytes == 2) + else if (byteDepth == 2) { *(UInt_16*)&buffer[i] = *(UInt_16*)&data[n]; } - else if (bytes == 3) + else if (byteDepth == 3) { buffer[i] = data[n]; buffer[i + 1] = data[n + 1]; buffer[i + 2] = data[n + 2]; } - else if (bytes == 4) + else if (byteDepth == 4) { *(UInt_32*)&buffer[i] = *(UInt_32*)&data[n]; } diff --git a/src/io/img/PNG.cpp b/src/io/img/PNG.cpp index 2f64cd0..f01b1b9 100644 --- a/src/io/img/PNG.cpp +++ b/src/io/img/PNG.cpp @@ -11,7 +11,7 @@ namespace ehs PNG::PNG(const Str_8& filePath) { - id = File::ProcessName_8(filePath); + id = File::ParseName_8(filePath); hashId = id.Hash_64(); File file(filePath, Mode::READ, Disposition::OPEN); diff --git a/src/io/model/Model.cpp b/src/io/model/Model.cpp index a46600f..e90f621 100644 --- a/src/io/model/Model.cpp +++ b/src/io/model/Model.cpp @@ -89,7 +89,7 @@ namespace ehs return id; } - Array Model::GetMeshes() const + const Array& Model::GetMeshes() const { return meshes; } @@ -113,7 +113,7 @@ namespace ehs return GetMesh(inId.Hash_64()); } - Bone Model::GetSkeleton() const + const Bone& Model::GetSkeleton() const { return skeleton; } @@ -132,7 +132,7 @@ namespace ehs return nullptr; } - Array Model::GetAnimations() const + const Array& Model::GetAnimations() const { return animations; }