CCITT fax decoder, finishing

This commit is contained in:
Jakub Melka
2019-10-13 19:02:38 +02:00
parent e20dfe6a5c
commit b1b5780753
4 changed files with 116 additions and 9 deletions

View File

@@ -20,6 +20,7 @@
#include "pdfconstants.h"
#include "pdfexception.h"
#include "pdfutils.h"
#include "pdfccittfaxdecoder.h"
#include <openjpeg.h>
#include <jpeglib.h>
@@ -166,6 +167,26 @@ PDFImage PDFImage::createImage(const PDFDocument* document, const PDFStream* str
}
}
const PDFDictionary* filterParamsDictionary = nullptr;
if (filterParameters.isDictionary())
{
filterParamsDictionary = filterParameters.getDictionary();
}
else if (filterParameters.isArray())
{
const PDFArray* filterParametersArray = filterParameters.getArray();
const size_t filterParamsCount = filterParametersArray->getCount();
if (filterParamsCount)
{
const PDFObject& object = document->getObject(filterParametersArray->getItem(filterParamsCount - 1));
if (object.isDictionary())
{
filterParamsDictionary = object.getDictionary();
}
}
}
if (imageFilterName == "DCTDecode" || imageFilterName == "DCT")
{
int colorTransform = loader.readIntegerFromDictionary(dictionary, "ColorTransform", -1);
@@ -493,7 +514,26 @@ PDFImage PDFImage::createImage(const PDFDocument* document, const PDFStream* str
}
else if (imageFilterName == "CCITTFaxDecode" || imageFilterName == "CCF")
{
throw PDFRendererException(RenderErrorType::NotImplemented, PDFTranslationContext::tr("Not implemented image filter 'CCITTFaxDecode'."));
if (!filterParamsDictionary)
{
throw PDFRendererException(RenderErrorType::Error, PDFTranslationContext::tr("Invalid parameters for filter CCITT fax decode."));
}
PDFCCITTFaxDecoderParameters parameters;
parameters.maskingType = maskingType;
parameters.K = loader.readIntegerFromDictionary(filterParamsDictionary, "K", 0);
parameters.hasEndOfLine = loader.readBooleanFromDictionary(filterParamsDictionary, "EndOfLine", false);
parameters.hasEncodedByteAlign = loader.readBooleanFromDictionary(filterParamsDictionary, "EncodedByteAlign", false);
parameters.columns = loader.readIntegerFromDictionary(filterParamsDictionary, "Columns", 1728);
parameters.rows = loader.readIntegerFromDictionary(filterParamsDictionary, "Rows", 0);
parameters.hasEndOfBlock = loader.readBooleanFromDictionary(filterParamsDictionary, "EndOfBlock", true);
parameters.hasBlackIsOne = loader.readBooleanFromDictionary(filterParamsDictionary, "BlackIs1", false);
parameters.damagedRowsBeforeError = loader.readIntegerFromDictionary(filterParamsDictionary, "DamagedRowsBeforeError", 0);
QByteArray imageDataBuffer = document->getDecodedStream(stream);
PDFCCITTFaxDecoder decoder(&imageDataBuffer, parameters);
image.m_imageData = decoder.decode();
}
else if (imageFilterName == "JBIG2Decode")
{