Non compressing png writer is ok.
This commit is contained in:
parent
33369b1775
commit
e4f9393ee7
18 changed files with 196 additions and 23 deletions
|
@ -22,6 +22,16 @@ void Image<T>::initialize()
|
|||
mData = std::vector<T>(getBytesPerRow()*mHeight, 10);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Image<T>::setDataItem(std::size_t index, T item)
|
||||
{
|
||||
if(index >= mData.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
mData[index] = item;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Image<T>::setPixelValue(unsigned idx, unsigned jdx, const Color& color)
|
||||
{
|
||||
|
|
|
@ -24,6 +24,8 @@ public:
|
|||
T getByte(unsigned idx, unsigned jdx) const;
|
||||
|
||||
void setData(const std::vector<T>& data);
|
||||
|
||||
void setDataItem(std::size_t index, T);
|
||||
void setWidth(unsigned width);
|
||||
void setHeight(unsigned height);
|
||||
void setBitDepth(unsigned bitDepth);
|
||||
|
|
|
@ -31,6 +31,12 @@ std::optional<unsigned char> ImageBitStream::readNextByte()
|
|||
|
||||
void ImageBitStream::writeByte(unsigned char data)
|
||||
{
|
||||
mByteOffset++;
|
||||
|
||||
if (isFinished() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
mImage->setDataItem(mByteOffset, data);
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,32 @@ public:
|
|||
|
||||
void decode()
|
||||
{
|
||||
auto image_stream = dynamic_cast<ImageBitStream*>(mOutputStream);
|
||||
if (!image_stream)
|
||||
{
|
||||
MLOG_ERROR("Expected ImageStream in PngFilter decode - aborting.");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto bytes_per_scanline = image_stream->getBytesPerScanline();
|
||||
unsigned count{0};
|
||||
|
||||
FilterType working_filter_type = FilterType::NONE;
|
||||
while(auto byte = mInputStream->readNextByte())
|
||||
{
|
||||
if (count % bytes_per_scanline == 0)
|
||||
{
|
||||
working_filter_type = static_cast<FilterType>(*byte);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (working_filter_type == FilterType::NONE)
|
||||
{
|
||||
image_stream->writeByte(*byte);
|
||||
}
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -13,6 +13,26 @@ public:
|
|||
|
||||
const std::vector<unsigned char>& getData() const;
|
||||
|
||||
uint32_t getWidth() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
uint32_t getHeight() const
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
unsigned char getBitDepth() const
|
||||
{
|
||||
return mBitDepth;
|
||||
}
|
||||
|
||||
const PngInfo& getPngInfo() const
|
||||
{
|
||||
return mPngInfo;
|
||||
}
|
||||
|
||||
unsigned char getHighBitCheck() const;
|
||||
|
||||
std::vector<unsigned char> getSignature() const;
|
||||
|
|
|
@ -19,6 +19,25 @@ std::string PngInfo::toString(ColorType colorType) const
|
|||
}
|
||||
}
|
||||
|
||||
unsigned PngInfo::getNumChannels() const
|
||||
{
|
||||
switch(mColorType)
|
||||
{
|
||||
case ColorType::GREYSCALE:
|
||||
return 1;
|
||||
case ColorType::RGB:
|
||||
return 3;
|
||||
case ColorType::PALETTE:
|
||||
return 1;
|
||||
case ColorType::GREYSCALE_ALPHA:
|
||||
return 2;
|
||||
case ColorType::RGB_ALPHA:
|
||||
return 4;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
std::string PngInfo::toString(CompressionMethod method) const
|
||||
{
|
||||
switch(method)
|
||||
|
|
|
@ -31,6 +31,8 @@ public:
|
|||
ADAM7 = 1
|
||||
};
|
||||
|
||||
unsigned getNumChannels() const;
|
||||
|
||||
std::string toString(ColorType colorType) const;
|
||||
|
||||
std::string toString(CompressionMethod method) const;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "BinaryStream.h"
|
||||
#include "BitStream.h"
|
||||
#include "BufferBitStream.h"
|
||||
#include "ImageBitStream.h"
|
||||
#include "PngFilter.h"
|
||||
|
||||
#include "ZlibEncoder.h"
|
||||
#include "CyclicRedundancyChecker.h"
|
||||
|
@ -180,6 +182,17 @@ std::unique_ptr<Image<unsigned char> > PngReader::read()
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
image->setWidth(mHeader.getWidth());
|
||||
image->setHeight(mHeader.getHeight());
|
||||
image->setBitDepth(mHeader.getBitDepth());
|
||||
image->setNumChannels(mHeader.getPngInfo().getNumChannels());
|
||||
image->initialize();
|
||||
|
||||
auto image_bit_stream = std::make_unique<ImageBitStream>(image.get());
|
||||
PngFilter filter(mOutputStream.get(), image_bit_stream.get());
|
||||
filter.decode();
|
||||
|
||||
return std::move(image);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue