diff --git a/JBIG2_Viewer/mainwindow.cpp b/JBIG2_Viewer/mainwindow.cpp index eb1f0f5..22509ac 100644 --- a/JBIG2_Viewer/mainwindow.cpp +++ b/JBIG2_Viewer/mainwindow.cpp @@ -102,7 +102,7 @@ void MainWindow::on_actionAdd_JBIG2_image_triggered() QImage image(imageData.getWidth(), imageData.getHeight(), QImage::Format_Mono); const uchar* sourceData = reinterpret_cast(imageData.getData().constData()); Q_ASSERT(imageData.getData().size() == image.byteCount()); - std::transform(sourceData, sourceData + imageData.getData().size(), image.bits(), [](const uchar value) { return ~value; }); + std::transform(sourceData, sourceData + imageData.getData().size(), image.bits(), [](const uchar value) { return value; }); addImage(file.fileName() + QString(", Decoded in %1 [msec]").arg(time), qMove(image)); } } diff --git a/PdfForQtLib/sources/pdfimage.cpp b/PdfForQtLib/sources/pdfimage.cpp index 4281b10..e84567a 100644 --- a/PdfForQtLib/sources/pdfimage.cpp +++ b/PdfForQtLib/sources/pdfimage.cpp @@ -670,6 +670,7 @@ PDFImage PDFImage::createImage(const PDFDocument* document, PDFJBIG2Decoder decoder(qMove(data), qMove(globalData), errorReporter); image.m_imageData = decoder.decode(maskingType); + image.m_imageData.setDecode(!decode.empty() ? qMove(decode) : std::vector({ 0.0, 1.0 })); } else if (colorSpace || isSoftMask) { diff --git a/PdfForQtLib/sources/pdfjbig2decoder.cpp b/PdfForQtLib/sources/pdfjbig2decoder.cpp index 0070313..aa1bee7 100644 --- a/PdfForQtLib/sources/pdfjbig2decoder.cpp +++ b/PdfForQtLib/sources/pdfjbig2decoder.cpp @@ -992,7 +992,7 @@ PDFImageData PDFJBIG2Decoder::decode(PDFImageData::MaskingType maskingType) { for (int column = 0; column < columns; ++column) { - writer.write(m_pageBitmap.getPixel(column, row)); + writer.write(!m_pageBitmap.getPixel(column, row)); } writer.finishLine(); } @@ -1205,8 +1205,8 @@ void PDFJBIG2Decoder::processSymbolDictionary(const PDFJBIG2SegmentHeader& heade parameters.isArithmeticCodingStateRetained = (symbolDictionaryFlags >> 9) & 0x0001; parameters.SDTEMPLATE = (symbolDictionaryFlags >> 10) & 0x0003; parameters.SDRTEMPLATE = (symbolDictionaryFlags >> 12) & 0x0001; - parameters.SDAT = readATTemplatePixelPositions((parameters.SDHUFF == 0) ? ((parameters.SDTEMPLATE == 0) ? 4 : 1) : 0); - parameters.SDRAT = readATTemplatePixelPositions((parameters.SDREFAGG == 1 && parameters.SDRTEMPLATE == 0) ? 2 : 0); + parameters.SDAT = readATTemplatePixelPositions((!parameters.SDHUFF) ? ((parameters.SDTEMPLATE == 0) ? 4 : 1) : 0); + parameters.SDRAT = readATTemplatePixelPositions((parameters.SDREFAGG && parameters.SDRTEMPLATE == 0) ? 2 : 0); parameters.SDNUMEXSYMS = m_reader.readUnsignedInt(); parameters.SDNUMNEWSYMS = m_reader.readUnsignedInt(); diff --git a/PdfForQtLib/sources/pdfutils.cpp b/PdfForQtLib/sources/pdfutils.cpp index 7e97490..40ed986 100644 --- a/PdfForQtLib/sources/pdfutils.cpp +++ b/PdfForQtLib/sources/pdfutils.cpp @@ -112,6 +112,11 @@ void PDFBitReader::alignToBytes() if (remainder > 0) { read(remainder); + + if (m_bitsInBuffer == 0) + { + m_buffer = 0; + } } }