Non compressing png writer is ok.

This commit is contained in:
James Grogan 2022-11-25 09:43:14 +00:00
parent 33369b1775
commit e4f9393ee7
18 changed files with 196 additions and 23 deletions

View file

@ -1,7 +1,11 @@
#include "File.h"
#include "FileLogger.h"
#include "ByteUtils.h"
#include <streambuf>
#include <fstream>
#include <sstream>
File::File(std::filesystem::path path)
: mFullPath(path),
@ -22,6 +26,30 @@ void File::SetAccessMode(AccessMode mode)
mAccessMode = mode;
}
std::string File::dumpBinary()
{
mAccessMode = AccessMode::Read;
Open();
std::stringstream sstr;
sstr << "Count | Binary | Decimal | ASCII \n";
unsigned count = 0;
while(mInHandle->peek() != EOF)
{
const unsigned char val = static_cast<unsigned char>(mInHandle->get());
const unsigned char ascii_val = std::isalpha(val) ? val : '.';
sstr << count << " | " << ByteUtils::toString(val) << " | " << static_cast<int>(val) << " | " << ascii_val << '\n';
if (count < 0 && count % 10 == 0)
{
sstr << "\n";
}
count++;
}
const auto out = sstr.str();
Close();
return out;
}
std::ifstream* File::GetInHandle() const
{
return mInHandle.get();

View file

@ -51,6 +51,8 @@ public:
std::optional<unsigned char> readNextByte();
std::string dumpBinary();
private:

View file

@ -30,11 +30,10 @@ void BitStream::write(uint32_t data)
void BitStream::writeWord(uint16_t data)
{
unsigned num_bytes = sizeof(uint16_t);
for(unsigned idx=0; idx<num_bytes;idx++)
{
writeByte(ByteUtils::getByteN(data, idx));
}
const auto byte0 = data >> 8;
const auto byte1 = (data << 8) >> 8;
writeByte(byte0);
writeByte(byte1);
}
int BitStream::getCurrentByteOffset() const

View file

@ -57,8 +57,6 @@ public:
mChecksumCalculator = nullptr;
}
//unsigned getSize() = 0;
protected:
int mByteOffset{-1};
unsigned mBitOffset{0};

View file

@ -11,7 +11,14 @@ std::vector<unsigned char> BufferBitStream::peekNextNBytes(unsigned n) const
{
std::vector<unsigned char> ret (n, 0);
unsigned count = 0;
for(unsigned idx=mByteOffset; idx<mByteOffset + n; idx++)
int start = mByteOffset;
if (start<0)
{
start = 0;
}
for(unsigned idx=start; idx<start + n; idx++)
{
if (idx == mBuffer.size())
{