2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-10 23:20:58 +00:00
qpdf/libqpdf/SF_FlateLzwDecode.cc
Jay Berkenbilt cb769c62e5 WHITESPACE ONLY -- expand tabs in source code
This comment expands all tabs using an 8-character tab-width. You
should ignore this commit when using git blame or use git blame -w.

In the early days, I used to use tabs where possible for indentation,
since emacs did this automatically. In recent years, I have switched
to only using spaces, which means qpdf source code has been a mixture
of spaces and tabs. I have avoided cleaning this up because of not
wanting gratuitous whitespaces change to cloud the output of git
blame, but I changed my mind after discussing with users who view qpdf
source code in editors/IDEs that have other tab widths by default and
in light of the fact that I am planning to start applying automatic
code formatting soon.
2022-02-08 11:51:15 -05:00

155 lines
4.1 KiB
C++

#include <qpdf/SF_FlateLzwDecode.hh>
#include <qpdf/Pl_PNGFilter.hh>
#include <qpdf/Pl_TIFFPredictor.hh>
#include <qpdf/Pl_Flate.hh>
#include <qpdf/Pl_LZWDecoder.hh>
#include <qpdf/QTC.hh>
#include <qpdf/QIntC.hh>
SF_FlateLzwDecode::SF_FlateLzwDecode(bool lzw) :
lzw(lzw),
// Initialize values to their defaults as per the PDF spec
predictor(1),
columns(0),
colors(1),
bits_per_component(8),
early_code_change(true)
{
}
bool
SF_FlateLzwDecode::setDecodeParms(QPDFObjectHandle decode_parms)
{
if (decode_parms.isNull())
{
return true;
}
bool filterable = true;
std::set<std::string> keys = decode_parms.getKeys();
for (auto const& key: keys)
{
QPDFObjectHandle value = decode_parms.getKey(key);
if (key == "/Predictor")
{
if (value.isInteger())
{
this->predictor = value.getIntValueAsInt();
if (! ((this->predictor == 1) || (this->predictor == 2) ||
((this->predictor >= 10) && (this->predictor <= 15))))
{
filterable = false;
}
}
else
{
filterable = false;
}
}
else if ((key == "/Columns") ||
(key == "/Colors") ||
(key == "/BitsPerComponent"))
{
if (value.isInteger())
{
int val = value.getIntValueAsInt();
if (key == "/Columns")
{
this->columns = val;
}
else if (key == "/Colors")
{
this->colors = val;
}
else if (key == "/BitsPerComponent")
{
this->bits_per_component = val;
}
}
else
{
filterable = false;
}
}
else if (lzw && (key == "/EarlyChange"))
{
if (value.isInteger())
{
int earlychange = value.getIntValueAsInt();
this->early_code_change = (earlychange == 1);
if (! ((earlychange == 0) || (earlychange == 1)))
{
filterable = false;
}
}
else
{
filterable = false;
}
}
}
if ((this->predictor > 1) && (this->columns == 0))
{
filterable = false;
}
return filterable;
}
Pipeline*
SF_FlateLzwDecode::getDecodePipeline(Pipeline* next)
{
std::shared_ptr<Pipeline> pipeline;
if ((this->predictor >= 10) && (this->predictor <= 15))
{
QTC::TC("qpdf", "SF_FlateLzwDecode PNG filter");
pipeline = std::make_shared<Pl_PNGFilter>(
"png decode", next, Pl_PNGFilter::a_decode,
QIntC::to_uint(this->columns),
QIntC::to_uint(this->colors),
QIntC::to_uint(this->bits_per_component));
this->pipelines.push_back(pipeline);
next = pipeline.get();
}
else if (this->predictor == 2)
{
QTC::TC("qpdf", "SF_FlateLzwDecode TIFF predictor");
pipeline = std::make_shared<Pl_TIFFPredictor>(
"tiff decode", next, Pl_TIFFPredictor::a_decode,
QIntC::to_uint(this->columns),
QIntC::to_uint(this->colors),
QIntC::to_uint(this->bits_per_component));
this->pipelines.push_back(pipeline);
next = pipeline.get();
}
if (lzw)
{
pipeline = std::make_shared<Pl_LZWDecoder>(
"lzw decode", next, early_code_change);
}
else
{
pipeline = std::make_shared<Pl_Flate>(
"stream inflate", next, Pl_Flate::a_inflate);
}
this->pipelines.push_back(pipeline);
return pipeline.get();
}
std::shared_ptr<QPDFStreamFilter>
SF_FlateLzwDecode::flate_factory()
{
return std::make_shared<SF_FlateLzwDecode>(false);
}
std::shared_ptr<QPDFStreamFilter>
SF_FlateLzwDecode::lzw_factory()
{
return std::make_shared<SF_FlateLzwDecode>(true);
}