2018-08-12 18:07:22 +00:00
|
|
|
#ifndef PL_PNGFILTER_HH
|
|
|
|
#define PL_PNGFILTER_HH
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
// This pipeline applies or reverses the application of a PNG filter as described in the PNG
|
|
|
|
// specification.
|
|
|
|
|
2017-11-07 17:12:18 +00:00
|
|
|
// NOTE: In its current implementation, this filter always encodes using the "up" filter, but it
|
|
|
|
// decodes all the filters.
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
#include <qpdf/Pipeline.hh>
|
|
|
|
|
2009-10-21 00:27:24 +00:00
|
|
|
class Pl_PNGFilter: public Pipeline
|
2008-04-29 12:55:25 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-01-13 18:21:23 +00:00
|
|
|
// Encoding is only partially supported
|
2008-04-29 12:55:25 +00:00
|
|
|
enum action_e { a_encode, a_decode };
|
|
|
|
|
|
|
|
Pl_PNGFilter(
|
|
|
|
char const* identifier,
|
|
|
|
Pipeline* next,
|
2022-02-08 14:18:08 +00:00
|
|
|
action_e action,
|
|
|
|
unsigned int columns,
|
2017-12-25 00:18:52 +00:00
|
|
|
unsigned int samples_per_pixel = 1,
|
|
|
|
unsigned int bits_per_sample = 8);
|
2023-05-20 13:25:46 +00:00
|
|
|
~Pl_PNGFilter() override = default;
|
2008-04-29 12:55:25 +00:00
|
|
|
|
2023-05-20 13:25:46 +00:00
|
|
|
void write(unsigned char const* data, size_t len) override;
|
|
|
|
void finish() override;
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
private:
|
2017-11-07 17:12:18 +00:00
|
|
|
void decodeSub();
|
|
|
|
void decodeUp();
|
|
|
|
void decodeAverage();
|
|
|
|
void decodePaeth();
|
2008-04-29 12:55:25 +00:00
|
|
|
void processRow();
|
|
|
|
void encodeRow();
|
|
|
|
void decodeRow();
|
2017-11-07 17:12:18 +00:00
|
|
|
int PaethPredictor(int a, int b, int c);
|
2008-04-29 12:55:25 +00:00
|
|
|
|
|
|
|
action_e action;
|
2017-12-25 00:18:52 +00:00
|
|
|
unsigned int bytes_per_row;
|
|
|
|
unsigned int bytes_per_pixel;
|
2019-06-22 18:24:49 +00:00
|
|
|
unsigned char* cur_row; // points to buf1 or buf2
|
|
|
|
unsigned char* prev_row; // points to buf1 or buf2
|
2022-04-09 18:35:56 +00:00
|
|
|
std::shared_ptr<unsigned char> buf1;
|
|
|
|
std::shared_ptr<unsigned char> buf2;
|
2012-06-20 15:20:57 +00:00
|
|
|
size_t pos;
|
|
|
|
size_t incoming;
|
2008-04-29 12:55:25 +00:00
|
|
|
};
|
|
|
|
|
2018-08-12 18:07:22 +00:00
|
|
|
#endif // PL_PNGFILTER_HH
|