Initial community commit
This commit is contained in:
parent
537bcbc862
commit
fc06254474
16440 changed files with 4239995 additions and 2 deletions
62
Src/external_dependencies/openmpt-trunk/include/ancient/src/DLTADecode.cpp
vendored
Normal file
62
Src/external_dependencies/openmpt-trunk/include/ancient/src/DLTADecode.cpp
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* Copyright (C) Teemu Suutari */
|
||||
|
||||
#include "DLTADecode.hpp"
|
||||
|
||||
#include "common/OverflowCheck.hpp"
|
||||
#include "common/Common.hpp"
|
||||
|
||||
|
||||
namespace ancient::internal
|
||||
{
|
||||
|
||||
bool DLTADecode::detectHeaderXPK(uint32_t hdr) noexcept
|
||||
{
|
||||
return hdr==FourCC("DLTA");
|
||||
}
|
||||
|
||||
std::shared_ptr<XPKDecompressor> DLTADecode::create(uint32_t hdr,uint32_t recursionLevel,const Buffer &packedData,std::shared_ptr<XPKDecompressor::State> &state,bool verify)
|
||||
{
|
||||
return std::make_shared<DLTADecode>(hdr,recursionLevel,packedData,state,verify);
|
||||
}
|
||||
|
||||
DLTADecode::DLTADecode(uint32_t hdr,uint32_t recursionLevel,const Buffer &packedData,std::shared_ptr<XPKDecompressor::State> &state,bool verify) :
|
||||
XPKDecompressor(recursionLevel),
|
||||
_packedData(packedData)
|
||||
{
|
||||
if (!detectHeaderXPK(hdr)) throw Decompressor::InvalidFormatError();
|
||||
}
|
||||
|
||||
DLTADecode::~DLTADecode()
|
||||
{
|
||||
// nothing needed
|
||||
}
|
||||
|
||||
const std::string &DLTADecode::getSubName() const noexcept
|
||||
{
|
||||
static std::string name="XPK-DLTA: Delta encoding";
|
||||
return name;
|
||||
}
|
||||
|
||||
void DLTADecode::decode(Buffer &bufferDest,const Buffer &bufferSrc,size_t offset,size_t size)
|
||||
{
|
||||
if (OverflowCheck::sum(offset,size)>bufferSrc.size()) throw Buffer::OutOfBoundsError();
|
||||
if (OverflowCheck::sum(offset,size)>bufferDest.size()) throw Buffer::OutOfBoundsError();
|
||||
const uint8_t *src=bufferSrc.data()+offset;
|
||||
uint8_t *dest=bufferDest.data()+offset;
|
||||
|
||||
uint8_t ctr=0;
|
||||
for (size_t i=0;i<size;i++)
|
||||
{
|
||||
ctr+=src[i];
|
||||
dest[i]=ctr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DLTADecode::decompressImpl(Buffer &rawData,const Buffer &previousData,bool verify)
|
||||
{
|
||||
if (rawData.size()<_packedData.size()) throw Decompressor::DecompressionError();
|
||||
decode(rawData,_packedData,0,_packedData.size());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue