Continue work on png writer.
This commit is contained in:
parent
9c8faa534b
commit
86bc0d89f6
19 changed files with 225 additions and 19 deletions
|
@ -21,6 +21,11 @@ unsigned char ByteUtils::getHigherNBits(unsigned char input, unsigned num)
|
|||
return input >> 8 - num;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getByteN(uint32_t input, unsigned n)
|
||||
{
|
||||
return (input << 8*n) >> 24;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getLowerNBits(unsigned char input, unsigned num)
|
||||
{
|
||||
switch (num)
|
||||
|
|
|
@ -17,6 +17,8 @@ public:
|
|||
|
||||
static Word GetWordLastByte(const Word word);
|
||||
|
||||
static unsigned char getByteN(uint32_t input, unsigned n);
|
||||
|
||||
static unsigned char getHigherNBits(unsigned char input, unsigned num);
|
||||
|
||||
static unsigned char getLowerNBits(unsigned char input, unsigned num);
|
||||
|
|
|
@ -32,9 +32,23 @@ std::ofstream* File::GetOutHandle() const
|
|||
return mOutHandle.get();
|
||||
}
|
||||
|
||||
unsigned char File::readNextByte()
|
||||
std::optional<unsigned char> File::readNextByte()
|
||||
{
|
||||
return mInHandle->get();
|
||||
if (mInHandle->good())
|
||||
{
|
||||
if (auto val = mInHandle->get(); val == EOF)
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
void File::Open(bool asBinary)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
using Path = std::filesystem::path;
|
||||
|
||||
|
@ -48,7 +49,7 @@ public:
|
|||
|
||||
void Close();
|
||||
|
||||
unsigned char readNextByte();
|
||||
std::optional<unsigned char> readNextByte();
|
||||
|
||||
|
||||
private:
|
||||
|
|
|
@ -27,6 +27,8 @@ public:
|
|||
|
||||
virtual void writeByte(unsigned char data) = 0;
|
||||
|
||||
virtual void writeBytes(const std::vector<unsigned char> data) = 0;
|
||||
|
||||
protected:
|
||||
int mByteOffset{0};
|
||||
unsigned mBitOffset{0};
|
||||
|
|
|
@ -17,6 +17,11 @@ public:
|
|||
|
||||
void writeByte(unsigned char data) override;
|
||||
|
||||
void writeBytes(const std::vector<unsigned char> data) override
|
||||
{
|
||||
std::copy(data.begin(), data.end(), std::back_inserter(mBuffer));
|
||||
}
|
||||
|
||||
const std::vector<unsigned char>& getBuffer() const
|
||||
{
|
||||
return mBuffer;
|
||||
|
|
|
@ -16,6 +16,11 @@ class InputBitStream : public BitStream
|
|||
|
||||
void writeByte(unsigned char data) override;
|
||||
|
||||
void writeBytes(const std::vector<unsigned char> data) override
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
std::basic_istream<unsigned char>* mStream{nullptr};
|
||||
};
|
||||
|
|
|
@ -26,3 +26,11 @@ void OutputBitStream::writeByte(unsigned char data)
|
|||
{
|
||||
(*mStream) << data;
|
||||
}
|
||||
|
||||
void OutputBitStream::writeBytes(const std::vector<unsigned char> data)
|
||||
{
|
||||
for(auto byte : data)
|
||||
{
|
||||
writeByte(byte);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ public:
|
|||
|
||||
void writeByte(unsigned char data) override;
|
||||
|
||||
void writeBytes(const std::vector<unsigned char> data) override;
|
||||
|
||||
private:
|
||||
std::basic_ostream<char>* mStream{nullptr};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue