Continue work on png writer.
This commit is contained in:
parent
9c8faa534b
commit
86bc0d89f6
19 changed files with 225 additions and 19 deletions
52
src/compression/CyclicRedundancyChecker.h
Normal file
52
src/compression/CyclicRedundancyChecker.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
#pragma once
|
||||
|
||||
class CyclicRedundancyChecker
|
||||
{
|
||||
public:
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private:
|
||||
bool mTableComputed{false};
|
||||
unsigned long mTable[256];
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue