Toward first png.

This commit is contained in:
James Grogan 2022-11-24 17:43:31 +00:00
parent 8f97e9b7a1
commit 33369b1775
12 changed files with 190 additions and 102 deletions

View file

@ -1,52 +1,20 @@
#pragma once
class CyclicRedundancyChecker
#include "AbstractChecksumCalculator.h"
class CyclicRedundancyChecker : public AbstractChecksumCalculator
{
public:
void addValue(unsigned char val) override;
void createTable()
{
unsigned long c{0};
for (int n = 0; n < 256; n++)
{
c = (unsigned long) n;
for (int k = 0; k < 8; k++)
{
if (c & 1)
{
c = 0xedb88320L ^ (c >> 1);
}
else
{
c = c >> 1;
}
}
mTable[n] = c;
}
mTableComputed = true;
mTableComputed = 1;
}
uint32_t getChecksum() const override;
unsigned long updateCrc(unsigned long crc, unsigned char *buf, int len)
{
unsigned long c = crc;
if (!mTableComputed)
{
createTable();
}
for (int n = 0; n < len; n++)
{
c = mTable[(c ^ buf[n]) & 0xff] ^ (c >> 8);
}
return c;
}
unsigned long doCrc(unsigned char *buf, int len)
{
return updateCrc(0xffffffffL, buf, len) ^ 0xffffffffL;
}
void reset() override;
private:
void createTable();
bool mTableComputed{false};
uint32_t mLastValue{0xffffffffL};
unsigned long mTable[256];
};