2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-02-10 23:58:31 +00:00

Code tidy SF_FlateLzwDecode

This commit is contained in:
m-holger 2025-02-05 12:32:52 +00:00
parent 2b470ff77c
commit a8631e255e
4 changed files with 26 additions and 30 deletions

View File

@ -18,3 +18,5 @@ d740c6ccced02147f84a39d5e5f0984d12bac6cb
9ae7bdea966102f9621b22192747a891078e7470
# Normalize white space in ChangeLog
d7b909f97d3effc9540c35b0251bdf1c9abf187c
# Remove 'this->'
f5cac93ac63559ddc0aec1b1c61c9e2503c7b8e0

View File

@ -117,8 +117,10 @@ ArgParser::argZopfli()
logger->info("Set the environment variable QPDF_ZOPFLI to activate.\n");
logger->info("* QPDF_ZOPFLI=disabled or QPDF_ZOPFLI not set: don't use zopfli.\n");
logger->info("* QPDF_ZOPFLI=force: use zopfli, and fail if not available.\n");
logger->info("* QPDF_ZOPFLI=silent: use zopfli if available and silently fall back if not.\n");
logger->info("* QPDF_ZOPFLI= any other value: use zopfli if available, and warn if not.\n");
logger->info(
"* QPDF_ZOPFLI=silent: use zopfli if available and silently fall back if not.\n");
logger->info(
"* QPDF_ZOPFLI= any other value: use zopfli if available, and warn if not.\n");
}
} else {
logger->error("zopfli support is not enabled\n");

View File

@ -7,17 +7,6 @@
#include <qpdf/QIntC.hh>
#include <qpdf/QTC.hh>
SF_FlateLzwDecode::SF_FlateLzwDecode(bool lzw) :
lzw(lzw),
// Initialize values to their defaults as per the PDF spec
predictor(1),
columns(1),
colors(1),
bits_per_component(8),
early_code_change(true)
{
}
bool
SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms)
{
@ -32,14 +21,13 @@ SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms)
if (key == "/Predictor") {
if (value.isInteger()) {
predictor = value.getIntValueAsInt();
if (!((predictor == 1) || (predictor == 2) ||
((predictor >= 10) && (predictor <= 15)))) {
if (!(predictor == 1 || predictor == 2 || (predictor >= 10 && predictor <= 15))) {
filterable = false;
}
} else {
filterable = false;
}
} else if ((key == "/Columns") || (key == "/Colors") || (key == "/BitsPerComponent")) {
} else if (key == "/Columns" || key == "/Colors" || key == "/BitsPerComponent") {
if (value.isInteger()) {
int val = value.getIntValueAsInt();
if (key == "/Columns") {
@ -56,7 +44,7 @@ SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms)
if (value.isInteger()) {
int earlychange = value.getIntValueAsInt();
early_code_change = (earlychange == 1);
if (!((earlychange == 0) || (earlychange == 1))) {
if (!(earlychange == 0 || earlychange == 1)) {
filterable = false;
}
} else {
@ -65,7 +53,7 @@ SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms)
}
}
if ((predictor > 1) && (columns == 0)) {
if (predictor > 1 && columns == 0) {
filterable = false;
}
@ -76,7 +64,7 @@ Pipeline*
SF_FlateLzwDecode::getDecodePipeline(Pipeline* next)
{
std::shared_ptr<Pipeline> pipeline;
if ((predictor >= 10) && (predictor <= 15)) {
if (predictor >= 10 && predictor <= 15) {
QTC::TC("qpdf", "SF_FlateLzwDecode PNG filter");
pipeline = std::make_shared<Pl_PNGFilter>(
"png decode",

View File

@ -5,25 +5,29 @@
#ifndef SF_FLATELZWDECODE_HH
# define SF_FLATELZWDECODE_HH
class SF_FlateLzwDecode: public QPDFStreamFilter
class SF_FlateLzwDecode final: public QPDFStreamFilter
{
public:
SF_FlateLzwDecode(bool lzw);
~SF_FlateLzwDecode() override = default;
SF_FlateLzwDecode(bool lzw) :
lzw(lzw)
{
}
~SF_FlateLzwDecode() final = default;
bool setDecodeParms(QPDFObjectHandle decode_parms) override;
Pipeline* getDecodePipeline(Pipeline* next) override;
bool setDecodeParms(QPDFObjectHandle decode_parms) final;
Pipeline* getDecodePipeline(Pipeline* next) final;
static std::shared_ptr<QPDFStreamFilter> flate_factory();
static std::shared_ptr<QPDFStreamFilter> lzw_factory();
private:
bool lzw;
int predictor;
int columns;
int colors;
int bits_per_component;
bool early_code_change;
bool lzw{};
// Defaults as per the PDF spec
int predictor{1};
int columns{1};
int colors{1};
int bits_per_component{8};
bool early_code_change{true};
std::vector<std::shared_ptr<Pipeline>> pipelines;
};