Continue work on png writer.
This commit is contained in:
parent
9c8faa534b
commit
86bc0d89f6
19 changed files with 225 additions and 19 deletions
|
@ -9,6 +9,8 @@
|
|||
|
||||
#include "Lz77Encoder.h"
|
||||
|
||||
#include "ByteUtils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
PngWriter::PngWriter()
|
||||
|
@ -34,15 +36,49 @@ void PngWriter::setPath(const Path& path)
|
|||
void PngWriter::writeSignature()
|
||||
{
|
||||
mOutStream->writeByte(Png::getHighBitCheck());
|
||||
for (auto byte : Png::getSignature())
|
||||
{
|
||||
mOutStream->writeByte(byte);
|
||||
}
|
||||
mOutStream->writeBytes(StringUtils::toBytes(Png::getName()));
|
||||
mOutStream->writeBytes(Png::getSignature());
|
||||
}
|
||||
|
||||
void PngWriter::writeHeader()
|
||||
{
|
||||
writeSignature();
|
||||
|
||||
Png::IHDRChunk header_chunk;
|
||||
header_chunk.width = mWorkingImage->getWidth();
|
||||
header_chunk.height = mWorkingImage->getHeight();
|
||||
header_chunk.bitDepth = mWorkingImage->getBitDepth();
|
||||
header_chunk.colorType = 6;
|
||||
|
||||
auto length = header_chunk.getLength();
|
||||
auto crc = header_chunk.getCrc();
|
||||
|
||||
unsigned num_bytes = sizeof(uint32_t);
|
||||
for(unsigned idx=0; idx<num_bytes;idx++)
|
||||
{
|
||||
mOutStream->writeByte(ByteUtils::getByteN(length, idx));
|
||||
}
|
||||
mOutStream->writeBytes(StringUtils::toBytes(header_chunk.name));
|
||||
|
||||
for(unsigned idx=0; idx<num_bytes;idx++)
|
||||
{
|
||||
mOutStream->writeByte(ByteUtils::getByteN(header_chunk.width, idx));
|
||||
}
|
||||
|
||||
for(unsigned idx=0; idx<num_bytes;idx++)
|
||||
{
|
||||
mOutStream->writeByte(ByteUtils::getByteN(header_chunk.height, idx));
|
||||
}
|
||||
mOutStream->writeByte(header_chunk.bitDepth);
|
||||
mOutStream->writeByte(header_chunk.colorType);
|
||||
mOutStream->writeByte(header_chunk.compressionMethod);
|
||||
mOutStream->writeByte(header_chunk.filterMethod);
|
||||
mOutStream->writeByte(header_chunk.interlaceMethod);
|
||||
|
||||
for(unsigned idx=0; idx<num_bytes;idx++)
|
||||
{
|
||||
mOutStream->writeByte(ByteUtils::getByteN(crc, idx));
|
||||
}
|
||||
}
|
||||
|
||||
void PngWriter::write(const std::unique_ptr<Image<unsigned char> >& image)
|
||||
|
@ -50,6 +86,7 @@ void PngWriter::write(const std::unique_ptr<Image<unsigned char> >& image)
|
|||
if (!mPath.empty())
|
||||
{
|
||||
mWorkingFile = std::make_unique<File>(mPath);
|
||||
mWorkingFile->SetAccessMode(File::AccessMode::Write);
|
||||
mWorkingFile->Open(true);
|
||||
mOutStream = std::make_unique<OutputBitStream>(mWorkingFile->GetOutHandle());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue