Circle buffer and png cleaning.
This commit is contained in:
parent
59cc910d58
commit
5400a232dd
13 changed files with 353 additions and 122 deletions
89
src/image/png/PngHeader.cpp
Normal file
89
src/image/png/PngHeader.cpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
#include "PngHeader.h"
|
||||
|
||||
#include "ByteUtils.h"
|
||||
#include "StringUtils.h"
|
||||
#include "CyclicRedundancyChecker.h"
|
||||
|
||||
std::string PngHeader::toString() const
|
||||
{
|
||||
std::stringstream sstr;
|
||||
sstr << "PngHeader" << "\n";
|
||||
sstr << "width: " << mWidth << "\n";
|
||||
sstr << "height: " << mHeight << "\n";
|
||||
sstr << "bitDepth: " << (int)mBitDepth << "\n";
|
||||
sstr << mPngInfo.toString();
|
||||
return sstr.str();
|
||||
}
|
||||
|
||||
uint32_t PngHeader::getLength() const
|
||||
{
|
||||
return 13;
|
||||
}
|
||||
|
||||
unsigned char PngHeader::getHighBitCheck() const
|
||||
{
|
||||
return 0x89;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> PngHeader::getSignature() const
|
||||
{
|
||||
return {13, 10, 26, 10};
|
||||
}
|
||||
|
||||
std::string PngHeader::getFileName() const
|
||||
{
|
||||
return "PNG";
|
||||
}
|
||||
|
||||
const std::string& PngHeader::getChunkName() const
|
||||
{
|
||||
return "IHDR";
|
||||
}
|
||||
|
||||
const std::vector<unsigned char>& PngHeader::getData() const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
void PngHeader::updateData()
|
||||
{
|
||||
mData.clear();
|
||||
unsigned num_bytes = sizeof(uint32_t);
|
||||
|
||||
for(unsigned idx=0; idx<num_bytes;idx++)
|
||||
{
|
||||
mData.push_back(ByteUtils::getByteN(mWidth, idx));
|
||||
}
|
||||
|
||||
for(unsigned idx=0; idx<num_bytes;idx++)
|
||||
{
|
||||
mData.push_back(ByteUtils::getByteN(mHeight, idx));
|
||||
}
|
||||
mData.push_back(mBitDepth);
|
||||
mData.push_back(static_cast<unsigned char>(mPngInfo.mColorType));
|
||||
mData.push_back(mPngInfo.mCompressionMethod);
|
||||
mData.push_back(mPngInfo.mFilterMethod);
|
||||
mData.push_back(mPngInfo.mInterlaceMethod);
|
||||
}
|
||||
|
||||
uint32_t PngHeader::getCrc() const
|
||||
{
|
||||
CyclicRedundancyChecker crc_check;
|
||||
std::vector<unsigned char> char_data = StringUtils::toBytes(mName);
|
||||
std::copy(mData.begin(), mData.end(), std::back_inserter(char_data));
|
||||
|
||||
auto result = crc_check.doCrc(char_data.data(), char_data.size());
|
||||
return result;
|
||||
}
|
||||
|
||||
void PngHeader::setPngInfo(const PngInfo& info)
|
||||
{
|
||||
mPngInfo = info;
|
||||
}
|
||||
|
||||
void PngHeader::setImageData(uint32_t width, uint32_t height, unsigned char bitDepth)
|
||||
{
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
mBitDepth = bitDepth;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue