2018-08-12 18:07:22 +00:00
|
|
|
#ifndef PL_LZWDECODER_HH
|
|
|
|
#define PL_LZWDECODER_HH
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
#include <qpdf/Pipeline.hh>
|
|
|
|
|
|
|
|
#include <qpdf/Buffer.hh>
|
|
|
|
#include <vector>
|
|
|
|
|
2009-10-21 00:27:24 +00:00
|
|
|
class Pl_LZWDecoder: public Pipeline
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Pl_LZWDecoder(char const* identifier, Pipeline* next, bool early_code_change);
|
2023-06-01 14:21:32 +00:00
|
|
|
~Pl_LZWDecoder() override = default;
|
|
|
|
void write(unsigned char const* buf, size_t len) override;
|
|
|
|
void finish() override;
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void sendNextCode();
|
2019-06-21 03:35:23 +00:00
|
|
|
void handleCode(unsigned int code);
|
|
|
|
unsigned char getFirstChar(unsigned int code);
|
2008-04-29 12:55:25 +00:00
|
|
|
void addToTable(unsigned char next);
|
|
|
|
|
|
|
|
// members used for converting bits to codes
|
|
|
|
unsigned char buf[3];
|
2019-06-21 03:35:23 +00:00
|
|
|
unsigned int code_size;
|
|
|
|
unsigned int next;
|
|
|
|
unsigned int byte_pos;
|
|
|
|
unsigned int bit_pos; // left to right: 01234567
|
|
|
|
unsigned int bits_available;
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
// members used for handle LZW decompression
|
|
|
|
bool code_change_delta;
|
|
|
|
bool eod;
|
|
|
|
std::vector<Buffer> table;
|
2019-06-21 03:35:23 +00:00
|
|
|
unsigned int last_code;
|
2008-04-29 12:55:25 +00:00
|
|
|
};
|
|
|
|
|
2018-08-12 18:07:22 +00:00
|
|
|
#endif // PL_LZWDECODER_HH
|