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