2024-02-05 22:25:30 -08:00
|
|
|
#include "ehs/io/img/ImgCodec.h"
|
|
|
|
#include "ehs/io/img/Img.h"
|
|
|
|
|
|
|
|
namespace ehs
|
|
|
|
{
|
|
|
|
ImgCodec::ImgCodec()
|
2024-02-20 22:47:52 -08:00
|
|
|
: hashExt(0), endianness(Endianness::LE), encoder(nullptr), decoder(nullptr)
|
2024-02-05 22:25:30 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-02-20 22:47:52 -08:00
|
|
|
ImgCodec::ImgCodec(Str_8 id, Str_8 ext, const Endianness end, EncodeImgCb encoder, DecodeImgCb decoder)
|
|
|
|
: id(std::move(id)), hashExt(ext.Hash_64()), ext(std::move(ext)), endianness(end), encoder(encoder),
|
|
|
|
decoder(decoder)
|
2024-02-05 22:25:30 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ImgCodec::ImgCodec(ImgCodec&& codec) noexcept
|
|
|
|
: id(std::move(codec.id)), hashExt(codec.hashExt), ext(std::move(codec.ext)), endianness(codec.endianness),
|
2024-02-20 22:47:52 -08:00
|
|
|
encoder(codec.encoder), decoder(codec.decoder)
|
2024-02-05 22:25:30 -08:00
|
|
|
{
|
|
|
|
codec.hashExt = 0;
|
|
|
|
codec.endianness = Endianness::LE;
|
2024-02-20 22:47:52 -08:00
|
|
|
codec.encoder = nullptr;
|
|
|
|
codec.decoder = nullptr;
|
2024-02-05 22:25:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
ImgCodec::ImgCodec(const ImgCodec& codec)
|
2024-02-20 22:47:52 -08:00
|
|
|
: id(codec.id), hashExt(codec.hashExt), ext(codec.ext), endianness(codec.endianness), encoder(codec.encoder),
|
|
|
|
decoder(codec.decoder)
|
2024-02-05 22:25:30 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ImgCodec& ImgCodec::operator=(ImgCodec&& codec) noexcept
|
|
|
|
{
|
|
|
|
if (this == &codec)
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
id = std::move(codec.id);
|
|
|
|
hashExt = codec.hashExt;
|
|
|
|
ext = std::move(codec.ext);
|
|
|
|
endianness = codec.endianness;
|
2024-02-20 22:47:52 -08:00
|
|
|
encoder = codec.encoder;
|
|
|
|
decoder = codec.decoder;
|
2024-02-05 22:25:30 -08:00
|
|
|
|
|
|
|
codec.hashExt = 0;
|
|
|
|
codec.endianness = Endianness::LE;
|
2024-02-20 22:47:52 -08:00
|
|
|
codec.encoder = nullptr;
|
|
|
|
codec.decoder = nullptr;
|
2024-02-05 22:25:30 -08:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImgCodec& ImgCodec::operator=(const ImgCodec& codec)
|
|
|
|
{
|
|
|
|
if (this == &codec)
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
id = codec.id;
|
|
|
|
hashExt = codec.hashExt;
|
|
|
|
ext = codec.ext;
|
|
|
|
endianness = codec.endianness;
|
2024-02-20 22:47:52 -08:00
|
|
|
encoder = codec.encoder;
|
|
|
|
decoder = codec.decoder;
|
2024-02-05 22:25:30 -08:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Str_8 ImgCodec::GetId() const
|
|
|
|
{
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
UInt_64 ImgCodec::GetHashExt() const
|
|
|
|
{
|
|
|
|
return hashExt;
|
|
|
|
}
|
|
|
|
|
|
|
|
Str_8 ImgCodec::GetExt() const
|
|
|
|
{
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
Endianness ImgCodec::GetEndianness() const
|
|
|
|
{
|
|
|
|
return endianness;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ImgCodec::Encode(Serializer<UInt_64>& out, const Img* in) const
|
|
|
|
{
|
2024-02-20 22:47:52 -08:00
|
|
|
if (!encoder)
|
2024-02-05 22:25:30 -08:00
|
|
|
{
|
|
|
|
EHS_LOG_INT("Error", 0, "Encoding is not supported for the " + id + " format.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-02-20 22:47:52 -08:00
|
|
|
return encoder(this, out, in);
|
2024-02-05 22:25:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ImgCodec::Decode(Serializer<UInt_64>& in, Img* out) const
|
|
|
|
{
|
2024-02-20 22:47:52 -08:00
|
|
|
if (!decoder)
|
2024-02-05 22:25:30 -08:00
|
|
|
{
|
|
|
|
EHS_LOG_INT("Error", 0, "Decoding is not supported for the " + id + " format.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-02-20 22:47:52 -08:00
|
|
|
return decoder(this, in, out);
|
2024-02-05 22:25:30 -08:00
|
|
|
}
|
|
|
|
}
|