Continue work on png writer.
This commit is contained in:
parent
9c8faa534b
commit
86bc0d89f6
19 changed files with 225 additions and 19 deletions
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "CyclicRedundancyChecker.h"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
|
@ -15,15 +17,23 @@ namespace Png
|
|||
return {13, 10, 26, 10};
|
||||
}
|
||||
|
||||
inline std::string getName()
|
||||
{
|
||||
return "PNG";
|
||||
}
|
||||
|
||||
struct IHDRChunk
|
||||
{
|
||||
unsigned width{0};
|
||||
unsigned height{0};
|
||||
char bitDepth{0};
|
||||
char colorType{0};
|
||||
char compressionMethod{0};
|
||||
char filterMethod{0};
|
||||
char interlaceMethod{0};
|
||||
uint32_t width{0};
|
||||
uint32_t height{0};
|
||||
unsigned char bitDepth{0};
|
||||
unsigned char colorType{0};
|
||||
unsigned char compressionMethod{0};
|
||||
unsigned char filterMethod{0};
|
||||
unsigned char interlaceMethod{0};
|
||||
std::string name{"IHDR"};
|
||||
|
||||
std::vector<unsigned char> mData;
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
|
@ -37,6 +47,42 @@ namespace Png
|
|||
sstr << "interlaceMethod: " << (int)interlaceMethod << "\n";
|
||||
return sstr.str();
|
||||
}
|
||||
|
||||
uint32_t getLength() const
|
||||
{
|
||||
return 13;
|
||||
}
|
||||
|
||||
void updateData()
|
||||
{
|
||||
mData.clear();
|
||||
unsigned num_bytes = sizeof(uint32_t);
|
||||
|
||||
for(unsigned idx=0; idx<num_bytes;idx++)
|
||||
{
|
||||
mData.push_back(ByteUtils::getByteN(width, idx));
|
||||
}
|
||||
|
||||
for(unsigned idx=0; idx<num_bytes;idx++)
|
||||
{
|
||||
mData.push_back(ByteUtils::getByteN(height, idx));
|
||||
}
|
||||
mData.push_back(bitDepth);
|
||||
mData.push_back(colorType);
|
||||
mData.push_back(compressionMethod);
|
||||
mData.push_back(filterMethod);
|
||||
mData.push_back(interlaceMethod);
|
||||
}
|
||||
|
||||
uint32_t getCrc() const
|
||||
{
|
||||
CyclicRedundancyChecker crc_check;
|
||||
std::vector<unsigned char> char_data = StringUtils::toBytes(name);
|
||||
std::copy(mData.begin(), mData.end(), std::back_inserter(char_data));
|
||||
|
||||
auto result = crc_check.doCrc(char_data.data(), char_data.size());
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue