109 lines
2.3 KiB
C++
109 lines
2.3 KiB
C++
#include "ehs/io/img/ImgCodec.h"
|
|
#include "ehs/io/img/Img.h"
|
|
|
|
namespace ehs
|
|
{
|
|
ImgCodec::ImgCodec()
|
|
: hashExt(0), endianness(Endianness::LE), encoder(nullptr), decoder(nullptr)
|
|
{
|
|
}
|
|
|
|
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)
|
|
{
|
|
}
|
|
|
|
ImgCodec::ImgCodec(ImgCodec&& codec) noexcept
|
|
: id(std::move(codec.id)), hashExt(codec.hashExt), ext(std::move(codec.ext)), endianness(codec.endianness),
|
|
encoder(codec.encoder), decoder(codec.decoder)
|
|
{
|
|
codec.hashExt = 0;
|
|
codec.endianness = Endianness::LE;
|
|
codec.encoder = nullptr;
|
|
codec.decoder = nullptr;
|
|
}
|
|
|
|
ImgCodec::ImgCodec(const ImgCodec& codec)
|
|
: id(codec.id), hashExt(codec.hashExt), ext(codec.ext), endianness(codec.endianness), encoder(codec.encoder),
|
|
decoder(codec.decoder)
|
|
{
|
|
}
|
|
|
|
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;
|
|
encoder = codec.encoder;
|
|
decoder = codec.decoder;
|
|
|
|
codec.hashExt = 0;
|
|
codec.endianness = Endianness::LE;
|
|
codec.encoder = nullptr;
|
|
codec.decoder = nullptr;
|
|
|
|
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;
|
|
encoder = codec.encoder;
|
|
decoder = codec.decoder;
|
|
|
|
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
|
|
{
|
|
if (!encoder)
|
|
{
|
|
EHS_LOG_INT(LogType::ERR, 0, "Encoding is not supported for the " + id + " format.");
|
|
return false;
|
|
}
|
|
|
|
return encoder(this, out, in);
|
|
}
|
|
|
|
bool ImgCodec::Decode(Serializer<UInt_64>& in, Img* out) const
|
|
{
|
|
if (!decoder)
|
|
{
|
|
EHS_LOG_INT(LogType::ERR, 0, "Decoding is not supported for the " + id + " format.");
|
|
return false;
|
|
}
|
|
|
|
return decoder(this, in, out);
|
|
}
|
|
} |