Restructured Img and FontAtlas.
This commit is contained in:
19
src/EHS.cpp
19
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<UInt_8>();
|
||||
if (compression)
|
||||
@@ -419,11 +419,10 @@ namespace ehs
|
||||
|
||||
bool EncodeQOI(const ehs::ImgCodec* const codec, ehs::Serializer<ehs::UInt_64>& 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<UInt_32> result(Endianness::BE, width * height * (channels + 1) + 22);
|
||||
Serializer<UInt_32> result(Endianness::BE, resolution.x * resolution.y * (channels + 1) + 22);
|
||||
|
||||
result.Write('q');
|
||||
result.Write('o');
|
||||
result.Write('i');
|
||||
result.Write('f');
|
||||
result.Write<UInt_32>(width);
|
||||
result.Write<UInt_32>(height);
|
||||
result.Write(in->Channels());
|
||||
result.Write<UInt_32>(resolution.x);
|
||||
result.Write<UInt_32>(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};
|
||||
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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<UInt_64>();
|
||||
height = fData.Read<UInt_64>();
|
||||
data = new Byte[width * height * (bitDepth / 8) * channels];
|
||||
fData.ReadArray(data, &size);
|
||||
resolution = fData.ReadVec2<UInt_64>();
|
||||
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<Glyph>&&)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<Glyph>&&)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<Glyph>();
|
||||
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<Vertex_f>&&)verts, (Array<UInt_32>&&)indices};
|
||||
}
|
||||
}
|
@@ -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)
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
|
@@ -89,7 +89,7 @@ namespace ehs
|
||||
return id;
|
||||
}
|
||||
|
||||
Array<Mesh> Model::GetMeshes() const
|
||||
const Array<Mesh>& 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<Animation> Model::GetAnimations() const
|
||||
const Array<Animation>& Model::GetAnimations() const
|
||||
{
|
||||
return animations;
|
||||
}
|
||||
|
Reference in New Issue
Block a user