Toward first png.
This commit is contained in:
parent
8f97e9b7a1
commit
33369b1775
12 changed files with 190 additions and 102 deletions
|
@ -83,9 +83,9 @@ void PngWriter::writeHeader()
|
|||
mPngHeader.updateData();
|
||||
mOutStream->writeBytes(mPngHeader.getData());
|
||||
|
||||
std::cout << "Writing header " << mPngHeader.toString() << std::endl;
|
||||
|
||||
auto crc = mPngHeader.getCrc();
|
||||
|
||||
std::cout << mPngHeader.toString() << "*********" << std::endl;
|
||||
mOutStream->write(crc);
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,11 @@ void PngWriter::writeEndChunk()
|
|||
std::vector<unsigned char> char_data = StringUtils::toBytes("IEND");
|
||||
|
||||
CyclicRedundancyChecker crc_check;
|
||||
auto crc = crc_check.doCrc(char_data.data(), char_data.size());
|
||||
for (auto c : char_data)
|
||||
{
|
||||
crc_check.addValue(c);
|
||||
}
|
||||
auto crc = crc_check.getChecksum();
|
||||
mOutStream->write(crc);
|
||||
|
||||
std::cout << "Writing end chunk" << std::endl;
|
||||
|
@ -108,11 +112,6 @@ void PngWriter::writeDataChunks(const BufferBitStream& buffer)
|
|||
{
|
||||
auto num_bytes = buffer.getBuffer().size();
|
||||
auto max_bytes{32000};
|
||||
std::vector<unsigned char> crc_buffer(num_bytes + 4, 0);
|
||||
crc_buffer[0] = 'I';
|
||||
crc_buffer[1] = 'D';
|
||||
crc_buffer[2] = 'A';
|
||||
crc_buffer[3] = 'T';
|
||||
|
||||
unsigned num_dat_chunks = num_bytes/max_bytes + 1;
|
||||
unsigned offset = 0;
|
||||
|
@ -127,18 +126,23 @@ void PngWriter::writeDataChunks(const BufferBitStream& buffer)
|
|||
std::cout << "Writing idat length " << num_bytes << std::endl;
|
||||
mOutStream->write(num_bytes);
|
||||
|
||||
mOutStream->writeBytes(StringUtils::toBytes("IDAT"));
|
||||
std::vector<unsigned char> char_data = StringUtils::toBytes("IDAT");
|
||||
mOutStream->writeBytes(char_data);
|
||||
|
||||
CyclicRedundancyChecker crc_check;
|
||||
for (auto c : char_data)
|
||||
{
|
||||
crc_check.addValue(c);
|
||||
}
|
||||
|
||||
for(unsigned jdx=0; jdx<num_bytes; jdx++)
|
||||
{
|
||||
auto val = buffer.getBuffer()[idx*max_bytes + jdx];
|
||||
crc_buffer[jdx + 4] = val;
|
||||
mOutStream->writeByte(val);
|
||||
crc_check.addValue(val);
|
||||
}
|
||||
|
||||
CyclicRedundancyChecker crc_check;
|
||||
auto crc = crc_check.doCrc(crc_buffer.data(), crc_buffer.size());
|
||||
|
||||
auto crc = crc_check.getChecksum();
|
||||
std::cout << "Writing idat crc" << crc << std::endl;
|
||||
mOutStream->write(crc);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue