[poppler] poppler/JBIG2Stream.cc poppler/JBIG2Stream.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Jan 3 21:34:38 UTC 2021


 poppler/JBIG2Stream.cc |  125 ++++++++++++++++++-------------------------------
 poppler/JBIG2Stream.h  |   18 +++----
 2 files changed, 56 insertions(+), 87 deletions(-)

New commits:
commit 8f599d8caf35911f168fd9dbc99a68dc1ac12a1c
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Sun Jan 3 08:56:17 2021 +0100

    JBIG2Stream: Store segments as std::unique_ptrs
    
    This makes the memory handling more error-proof, because
    all necessary calls to 'delete' happen automatically.
    
    This patch introduces several calls to std::unique_ptr::release,
    and hence break the explicit ownership chain established
    by using std::unique_ptr.  Not all of the calls are strictly
    necessary, but without them the patch would get a lot
    bigger than it is.  Better keep that for another day.

diff --git a/poppler/JBIG2Stream.cc b/poppler/JBIG2Stream.cc
index a2e4169b..308bf772 100644
--- a/poppler/JBIG2Stream.cc
+++ b/poppler/JBIG2Stream.cc
@@ -1146,7 +1146,8 @@ JBIG2Stream::~JBIG2Stream()
 
 void JBIG2Stream::reset()
 {
-    freeSegments();
+    segments.resize(0);
+    globalSegments.resize(0);
 
     // read the globals stream
     if (globalsStream.isStream()) {
@@ -1177,26 +1178,14 @@ void JBIG2Stream::reset()
     }
 }
 
-void JBIG2Stream::freeSegments()
-{
-    for (auto entry : segments) {
-        delete entry;
-    }
-    segments.resize(0);
-
-    for (auto entry : globalSegments) {
-        delete entry;
-    }
-    globalSegments.resize(0);
-}
-
 void JBIG2Stream::close()
 {
     if (pageBitmap) {
         delete pageBitmap;
         pageBitmap = nullptr;
     }
-    freeSegments();
+    segments.resize(0);
+    globalSegments.resize(0);
     dataPtr = dataEnd = nullptr;
     FilterStream::close();
 }
@@ -1462,7 +1451,7 @@ eofError1:
 
 bool JBIG2Stream::readSymbolDictSeg(unsigned int segNum, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs)
 {
-    JBIG2SymbolDict *symbolDict;
+    std::unique_ptr<JBIG2SymbolDict> symbolDict;
     const JBIG2HuffmanTable *huffDHTable, *huffDWTable;
     const JBIG2HuffmanTable *huffBMSizeTable, *huffAggInstTable;
     JBIG2Segment *seg;
@@ -1752,11 +1741,12 @@ bool JBIG2Stream::readSymbolDictSeg(unsigned int segNum, unsigned int length, un
                         error(errSyntaxError, curStr->getPos(), "Invalid ref bitmap for symbol ID {0:ud} in JBIG2 symbol dictionary", symID);
                         goto syntaxError;
                     }
-                    bitmaps[numInputSyms + i] = readGenericRefinementRegion(symWidth, symHeight, sdrTemplate, false, refBitmap, refDX, refDY, sdrATX, sdrATY);
+                    bitmaps[numInputSyms + i] = readGenericRefinementRegion(symWidth, symHeight, sdrTemplate, false, refBitmap, refDX, refDY, sdrATX, sdrATY).release();
                     //~ do we need to use the bmSize value here (in Huffman mode)?
                 } else {
                     bitmaps[numInputSyms + i] = readTextRegion(huff, true, symWidth, symHeight, refAggNum, 0, numInputSyms + i, nullptr, symCodeLen, bitmaps, 0, 0, 0, 1, 0, huffTableF, huffTableH, huffTableK, huffTableO, huffTableO,
-                                                               huffTableO, huffTableO, huffTableA, sdrTemplate, sdrATX, sdrATY);
+                                                               huffTableO, huffTableO, huffTableA, sdrTemplate, sdrATX, sdrATY)
+                                                        .release();
                     if (unlikely(!bitmaps[numInputSyms + i])) {
                         error(errSyntaxError, curStr->getPos(), "NULL bitmap in readTextRegion");
                         goto syntaxError;
@@ -1765,7 +1755,7 @@ bool JBIG2Stream::readSymbolDictSeg(unsigned int segNum, unsigned int length, un
 
                 // non-ref/agg coding
             } else {
-                bitmaps[numInputSyms + i] = readGenericBitmap(false, symWidth, symHeight, sdTemplate, false, false, nullptr, sdATX, sdATY, 0);
+                bitmaps[numInputSyms + i] = readGenericBitmap(false, symWidth, symHeight, sdTemplate, false, false, nullptr, sdATX, sdATY, 0).release();
             }
 
             ++i;
@@ -1791,7 +1781,7 @@ bool JBIG2Stream::readSymbolDictSeg(unsigned int segNum, unsigned int length, un
                     *p++ = (unsigned char)c;
                 }
             } else {
-                collBitmap = readGenericBitmap(true, totalWidth, symHeight, 0, false, false, nullptr, nullptr, nullptr, bmSize);
+                collBitmap = readGenericBitmap(true, totalWidth, symHeight, 0, false, false, nullptr, nullptr, nullptr, bmSize).release();
             }
             if (likely(collBitmap != nullptr)) {
                 x = 0;
@@ -1808,9 +1798,8 @@ bool JBIG2Stream::readSymbolDictSeg(unsigned int segNum, unsigned int length, un
     }
 
     // create the symbol dict object
-    symbolDict = new JBIG2SymbolDict(segNum, numExSyms);
+    symbolDict = std::make_unique<JBIG2SymbolDict>(segNum, numExSyms);
     if (!symbolDict->isOk()) {
-        delete symbolDict;
         goto syntaxError;
     }
 
@@ -1829,7 +1818,6 @@ bool JBIG2Stream::readSymbolDictSeg(unsigned int segNum, unsigned int length, un
             error(errSyntaxError, curStr->getPos(), "Too many exported symbols in JBIG2 symbol dictionary");
             for (; j < numExSyms; ++j)
                 symbolDict->setBitmap(j, nullptr);
-            delete symbolDict;
             goto syntaxError;
         }
         if (ex) {
@@ -1845,7 +1833,6 @@ bool JBIG2Stream::readSymbolDictSeg(unsigned int segNum, unsigned int length, un
         error(errSyntaxError, curStr->getPos(), "Too few symbols in JBIG2 symbol dictionary");
         for (; j < numExSyms; ++j)
             symbolDict->setBitmap(j, nullptr);
-        delete symbolDict;
         goto syntaxError;
     }
 
@@ -1866,7 +1853,7 @@ bool JBIG2Stream::readSymbolDictSeg(unsigned int segNum, unsigned int length, un
     }
 
     // store the new symbol dict
-    segments.push_back(symbolDict);
+    segments.push_back(std::move(symbolDict));
 
     return true;
 
@@ -1892,7 +1879,7 @@ eofError:
 
 void JBIG2Stream::readTextRegionSeg(unsigned int segNum, bool imm, bool lossless, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs)
 {
-    JBIG2Bitmap *bitmap;
+    std::unique_ptr<JBIG2Bitmap> bitmap;
     JBIG2HuffmanTable runLengthTab[36];
     JBIG2HuffmanTable *symCodeTab = nullptr;
     const JBIG2HuffmanTable *huffFSTable, *huffDSTable, *huffDTTable;
@@ -2174,13 +2161,12 @@ void JBIG2Stream::readTextRegionSeg(unsigned int segNum, bool imm, bool lossless
             if (pageH == 0xffffffff && y + h > curPageH) {
                 pageBitmap->expand(y + h, pageDefPixel);
             }
-            pageBitmap->combine(bitmap, x, y, extCombOp);
-            delete bitmap;
+            pageBitmap->combine(bitmap.get(), x, y, extCombOp);
 
             // store the region bitmap
         } else {
             bitmap->setSegNum(segNum);
-            segments.push_back(bitmap);
+            segments.push_back(std::move(bitmap));
         }
     }
 
@@ -2201,10 +2187,10 @@ eofError:
     return;
 }
 
-JBIG2Bitmap *JBIG2Stream::readTextRegion(bool huff, bool refine, int w, int h, unsigned int numInstances, unsigned int logStrips, int numSyms, const JBIG2HuffmanTable *symCodeTab, unsigned int symCodeLen, JBIG2Bitmap **syms,
-                                         unsigned int defPixel, unsigned int combOp, unsigned int transposed, unsigned int refCorner, int sOffset, const JBIG2HuffmanTable *huffFSTable, const JBIG2HuffmanTable *huffDSTable,
-                                         const JBIG2HuffmanTable *huffDTTable, const JBIG2HuffmanTable *huffRDWTable, const JBIG2HuffmanTable *huffRDHTable, const JBIG2HuffmanTable *huffRDXTable, const JBIG2HuffmanTable *huffRDYTable,
-                                         const JBIG2HuffmanTable *huffRSizeTable, unsigned int templ, int *atx, int *aty)
+std::unique_ptr<JBIG2Bitmap> JBIG2Stream::readTextRegion(bool huff, bool refine, int w, int h, unsigned int numInstances, unsigned int logStrips, int numSyms, const JBIG2HuffmanTable *symCodeTab, unsigned int symCodeLen, JBIG2Bitmap **syms,
+                                                         unsigned int defPixel, unsigned int combOp, unsigned int transposed, unsigned int refCorner, int sOffset, const JBIG2HuffmanTable *huffFSTable, const JBIG2HuffmanTable *huffDSTable,
+                                                         const JBIG2HuffmanTable *huffDTTable, const JBIG2HuffmanTable *huffRDWTable, const JBIG2HuffmanTable *huffRDHTable, const JBIG2HuffmanTable *huffRDXTable,
+                                                         const JBIG2HuffmanTable *huffRDYTable, const JBIG2HuffmanTable *huffRSizeTable, unsigned int templ, int *atx, int *aty)
 {
     JBIG2Bitmap *symbolBitmap;
     unsigned int strips;
@@ -2328,7 +2314,7 @@ JBIG2Bitmap *JBIG2Stream::readTextRegion(bool huff, bool refine, int w, int h, u
                         refDX = ((rdw >= 0) ? rdw : rdw - 1) / 2 + rdx;
                         refDY = ((rdh >= 0) ? rdh : rdh - 1) / 2 + rdy;
 
-                        symbolBitmap = readGenericRefinementRegion(rdw + syms[symID]->getWidth(), rdh + syms[symID]->getHeight(), templ, false, syms[symID], refDX, refDY, atx, aty);
+                        symbolBitmap = readGenericRefinementRegion(rdw + syms[symID]->getWidth(), rdh + syms[symID]->getHeight(), templ, false, syms[symID], refDX, refDY, atx, aty).release();
                     }
                     //~ do we need to use the bmSize value here (in Huffman mode)?
                 } else {
@@ -2444,13 +2430,13 @@ JBIG2Bitmap *JBIG2Stream::readTextRegion(bool huff, bool refine, int w, int h, u
         }
     }
 
-    return bitmap.release();
+    return bitmap;
 }
 
 void JBIG2Stream::readPatternDictSeg(unsigned int segNum, unsigned int length)
 {
-    JBIG2PatternDict *patternDict;
-    JBIG2Bitmap *bitmap;
+    std::unique_ptr<JBIG2PatternDict> patternDict;
+    std::unique_ptr<JBIG2Bitmap> bitmap;
     unsigned int flags, patternW, patternH, grayMax, templ, mmr;
     int atx[4], aty[4];
     unsigned int i, x;
@@ -2483,7 +2469,7 @@ void JBIG2Stream::readPatternDictSeg(unsigned int segNum, unsigned int length)
         return;
 
     // create the pattern dict object
-    patternDict = new JBIG2PatternDict(segNum, grayMax + 1);
+    patternDict = std::make_unique<JBIG2PatternDict>(segNum, grayMax + 1);
 
     // split up the bitmap
     x = 0;
@@ -2492,11 +2478,8 @@ void JBIG2Stream::readPatternDictSeg(unsigned int segNum, unsigned int length)
         x += patternW;
     }
 
-    // free memory
-    delete bitmap;
-
     // store the new pattern dict
-    segments.push_back(patternDict);
+    segments.push_back(std::move(patternDict));
 
     return;
 
@@ -2506,12 +2489,11 @@ eofError:
 
 void JBIG2Stream::readHalftoneRegionSeg(unsigned int segNum, bool imm, bool lossless, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs)
 {
-    JBIG2Bitmap *bitmap;
+    std::unique_ptr<JBIG2Bitmap> bitmap;
     JBIG2Segment *seg;
     JBIG2PatternDict *patternDict;
     JBIG2Bitmap *skipBitmap;
     unsigned int *grayImg;
-    JBIG2Bitmap *grayBitmap;
     JBIG2Bitmap *patternBitmap;
     unsigned int w, h, x, y, segInfoFlags, extCombOp;
     unsigned int flags, mmr, templ, enableSkip, combOp;
@@ -2585,7 +2567,7 @@ void JBIG2Stream::readHalftoneRegionSeg(unsigned int segNum, bool imm, bool loss
     }
 
     // allocate the bitmap
-    bitmap = new JBIG2Bitmap(segNum, w, h);
+    bitmap = std::make_unique<JBIG2Bitmap>(segNum, w, h);
     if (flags & 0x80) { // HDEFPIXEL
         bitmap->clearToOne();
     } else {
@@ -2620,7 +2602,7 @@ void JBIG2Stream::readHalftoneRegionSeg(unsigned int segNum, bool imm, bool loss
     atx[3] = -2;
     aty[3] = -2;
     for (j = bpp - 1; j >= 0; --j) {
-        grayBitmap = readGenericBitmap(mmr, gridW, gridH, templ, false, enableSkip, skipBitmap, atx, aty, -1);
+        std::unique_ptr<JBIG2Bitmap> grayBitmap = readGenericBitmap(mmr, gridW, gridH, templ, false, enableSkip, skipBitmap, atx, aty, -1);
         i = 0;
         for (m = 0; m < gridH; ++m) {
             for (n = 0; n < gridW; ++n) {
@@ -2629,7 +2611,6 @@ void JBIG2Stream::readHalftoneRegionSeg(unsigned int segNum, bool imm, bool loss
                 ++i;
             }
         }
-        delete grayBitmap;
     }
 
     // decode the image
@@ -2642,7 +2623,6 @@ void JBIG2Stream::readHalftoneRegionSeg(unsigned int segNum, bool imm, bool loss
                 patternBitmap = patternDict->getBitmap(grayImg[i]);
                 if (unlikely(patternBitmap == nullptr)) {
                     delete skipBitmap;
-                    delete bitmap;
                     gfree(grayImg);
                     error(errSyntaxError, curStr->getPos(), "Bad pattern bitmap");
                     return;
@@ -2665,12 +2645,11 @@ void JBIG2Stream::readHalftoneRegionSeg(unsigned int segNum, bool imm, bool loss
         if (pageH == 0xffffffff && y + h > curPageH) {
             pageBitmap->expand(y + h, pageDefPixel);
         }
-        pageBitmap->combine(bitmap, x, y, extCombOp);
-        delete bitmap;
+        pageBitmap->combine(bitmap.get(), x, y, extCombOp);
 
         // store the region bitmap
     } else {
-        segments.push_back(bitmap);
+        segments.push_back(std::move(bitmap));
     }
 
     return;
@@ -2681,7 +2660,7 @@ eofError:
 
 void JBIG2Stream::readGenericRegionSeg(unsigned int segNum, bool imm, bool lossless, unsigned int length)
 {
-    JBIG2Bitmap *bitmap;
+    std::unique_ptr<JBIG2Bitmap> bitmap;
     unsigned int w, h, x, y, segInfoFlags, extCombOp, rowCount;
     unsigned int flags, mmr, templ, tpgdOn;
     int atx[4], aty[4];
@@ -2729,13 +2708,12 @@ void JBIG2Stream::readGenericRegionSeg(unsigned int segNum, bool imm, bool lossl
         if (pageH == 0xffffffff && y + h > curPageH) {
             pageBitmap->expand(y + h, pageDefPixel);
         }
-        pageBitmap->combine(bitmap, x, y, extCombOp);
-        delete bitmap;
+        pageBitmap->combine(bitmap.get(), x, y, extCombOp);
 
         // store the region bitmap
     } else {
         bitmap->setSegNum(segNum);
-        segments.push_back(bitmap);
+        segments.push_back(std::move(bitmap));
     }
 
     // immediate generic segments can have an unspecified length, in
@@ -2787,9 +2765,8 @@ inline void JBIG2Stream::mmrAddPixelsNeg(int a1, int blackPixels, int *codingLin
     }
 }
 
-JBIG2Bitmap *JBIG2Stream::readGenericBitmap(bool mmr, int w, int h, int templ, bool tpgdOn, bool useSkip, JBIG2Bitmap *skip, int *atx, int *aty, int mmrDataLength)
+std::unique_ptr<JBIG2Bitmap> JBIG2Stream::readGenericBitmap(bool mmr, int w, int h, int templ, bool tpgdOn, bool useSkip, JBIG2Bitmap *skip, int *atx, int *aty, int mmrDataLength)
 {
-    JBIG2Bitmap *bitmap;
     bool ltp;
     unsigned int ltpCX, cx, cx0, cx1, cx2;
     int *refLine, *codingLine;
@@ -2802,9 +2779,8 @@ JBIG2Bitmap *JBIG2Stream::readGenericBitmap(bool mmr, int w, int h, int templ, b
     unsigned char mask;
     int x, y, x0, x1, a0i, b1i, blackPixels, pix, i;
 
-    bitmap = new JBIG2Bitmap(0, w, h);
+    auto bitmap = std::make_unique<JBIG2Bitmap>(0, w, h);
     if (!bitmap->isOk()) {
-        delete bitmap;
         return nullptr;
     }
     bitmap->clearToZero();
@@ -2823,7 +2799,6 @@ JBIG2Bitmap *JBIG2Stream::readGenericBitmap(bool mmr, int w, int h, int templ, b
 
         if (unlikely(!codingLine || !refLine)) {
             error(errSyntaxError, curStr->getPos(), "Bad width in JBIG2 generic bitmap");
-            delete bitmap;
             return nullptr;
         }
 
@@ -3557,7 +3532,8 @@ JBIG2Bitmap *JBIG2Stream::readGenericBitmap(bool mmr, int w, int h, int templ, b
 
 void JBIG2Stream::readGenericRefinementRegionSeg(unsigned int segNum, bool imm, bool lossless, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs)
 {
-    JBIG2Bitmap *bitmap, *refBitmap;
+    std::unique_ptr<JBIG2Bitmap> bitmap;
+    JBIG2Bitmap *refBitmap;
     unsigned int w, h, x, y, segInfoFlags, extCombOp;
     unsigned int flags, templ, tpgrOn;
     int atx[2], aty[2];
@@ -3615,14 +3591,13 @@ void JBIG2Stream::readGenericRefinementRegionSeg(unsigned int segNum, bool imm,
 
     // combine the region bitmap into the page bitmap
     if (imm && bitmap) {
-        pageBitmap->combine(bitmap, x, y, extCombOp);
-        delete bitmap;
+        pageBitmap->combine(bitmap.get(), x, y, extCombOp);
 
         // store the region bitmap
     } else {
         if (bitmap) {
             bitmap->setSegNum(segNum);
-            segments.push_back(bitmap);
+            segments.push_back(std::move(bitmap));
         } else {
             error(errSyntaxError, curStr->getPos(), "readGenericRefinementRegionSeg with null bitmap");
         }
@@ -3641,9 +3616,8 @@ eofError:
     error(errSyntaxError, curStr->getPos(), "Unexpected EOF in JBIG2 stream");
 }
 
-JBIG2Bitmap *JBIG2Stream::readGenericRefinementRegion(int w, int h, int templ, bool tpgrOn, JBIG2Bitmap *refBitmap, int refDX, int refDY, int *atx, int *aty)
+std::unique_ptr<JBIG2Bitmap> JBIG2Stream::readGenericRefinementRegion(int w, int h, int templ, bool tpgrOn, JBIG2Bitmap *refBitmap, int refDX, int refDY, int *atx, int *aty)
 {
-    JBIG2Bitmap *bitmap;
     bool ltp;
     unsigned int ltpCX, cx, cx0, cx2, cx3, cx4, tpgrCX0, tpgrCX1, tpgrCX2;
     JBIG2BitmapPtr cxPtr0 = { nullptr, 0, 0 };
@@ -3662,9 +3636,8 @@ JBIG2Bitmap *JBIG2Stream::readGenericRefinementRegion(int w, int h, int templ, b
         return nullptr;
     }
 
-    bitmap = new JBIG2Bitmap(0, w, h);
+    auto bitmap = std::make_unique<JBIG2Bitmap>(0, w, h);
     if (!bitmap->isOk()) {
-        delete bitmap;
         return nullptr;
     }
     bitmap->clearToZero();
@@ -3943,7 +3916,7 @@ void JBIG2Stream::readCodeTableSeg(unsigned int segNum, unsigned int length)
     huffTab[i].rangeLen = jbig2HuffmanEOT;
     if (JBIG2HuffmanDecoder::buildTable(huffTab, i)) {
         // create and store the new table segment
-        segments.push_back(new JBIG2CodeTable(segNum, huffTab));
+        segments.push_back(std::make_unique<JBIG2CodeTable>(segNum, huffTab));
     } else {
         free(huffTab);
     }
@@ -3964,14 +3937,14 @@ void JBIG2Stream::readExtensionSeg(unsigned int length)
 
 JBIG2Segment *JBIG2Stream::findSegment(unsigned int segNum)
 {
-    for (JBIG2Segment *seg : globalSegments) {
+    for (std::unique_ptr<JBIG2Segment> &seg : globalSegments) {
         if (seg->getSegNum() == segNum) {
-            return seg;
+            return seg.get();
         }
     }
-    for (JBIG2Segment *seg : segments) {
+    for (std::unique_ptr<JBIG2Segment> &seg : segments) {
         if (seg->getSegNum() == segNum) {
-            return seg;
+            return seg.get();
         }
     }
     return nullptr;
@@ -3980,15 +3953,13 @@ JBIG2Segment *JBIG2Stream::findSegment(unsigned int segNum)
 void JBIG2Stream::discardSegment(unsigned int segNum)
 {
     for (auto it = globalSegments.begin(); it != globalSegments.end(); ++it) {
-        auto seg = static_cast<JBIG2Segment *>(*it);
-        if (seg->getSegNum() == segNum) {
+        if ((*it)->getSegNum() == segNum) {
             globalSegments.erase(it);
             return;
         }
     }
     for (auto it = segments.begin(); it != segments.end(); ++it) {
-        auto seg = static_cast<JBIG2Segment *>(*it);
-        if (seg->getSegNum() == segNum) {
+        if ((*it)->getSegNum() == segNum) {
             segments.erase(it);
             return;
         }
diff --git a/poppler/JBIG2Stream.h b/poppler/JBIG2Stream.h
index abc94ccd..f3da7586 100644
--- a/poppler/JBIG2Stream.h
+++ b/poppler/JBIG2Stream.h
@@ -62,23 +62,21 @@ private:
     bool hasGetChars() override { return true; }
     int getChars(int nChars, unsigned char *buffer) override;
 
-    void freeSegments();
-
     void readSegments();
     bool readSymbolDictSeg(unsigned int segNum, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs);
     void readTextRegionSeg(unsigned int segNum, bool imm, bool lossless, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs);
-    JBIG2Bitmap *readTextRegion(bool huff, bool refine, int w, int h, unsigned int numInstances, unsigned int logStrips, int numSyms, const JBIG2HuffmanTable *symCodeTab, unsigned int symCodeLen, JBIG2Bitmap **syms, unsigned int defPixel,
-                                unsigned int combOp, unsigned int transposed, unsigned int refCorner, int sOffset, const JBIG2HuffmanTable *huffFSTable, const JBIG2HuffmanTable *huffDSTable, const JBIG2HuffmanTable *huffDTTable,
-                                const JBIG2HuffmanTable *huffRDWTable, const JBIG2HuffmanTable *huffRDHTable, const JBIG2HuffmanTable *huffRDXTable, const JBIG2HuffmanTable *huffRDYTable, const JBIG2HuffmanTable *huffRSizeTable,
-                                unsigned int templ, int *atx, int *aty);
+    std::unique_ptr<JBIG2Bitmap> readTextRegion(bool huff, bool refine, int w, int h, unsigned int numInstances, unsigned int logStrips, int numSyms, const JBIG2HuffmanTable *symCodeTab, unsigned int symCodeLen, JBIG2Bitmap **syms,
+                                                unsigned int defPixel, unsigned int combOp, unsigned int transposed, unsigned int refCorner, int sOffset, const JBIG2HuffmanTable *huffFSTable, const JBIG2HuffmanTable *huffDSTable,
+                                                const JBIG2HuffmanTable *huffDTTable, const JBIG2HuffmanTable *huffRDWTable, const JBIG2HuffmanTable *huffRDHTable, const JBIG2HuffmanTable *huffRDXTable,
+                                                const JBIG2HuffmanTable *huffRDYTable, const JBIG2HuffmanTable *huffRSizeTable, unsigned int templ, int *atx, int *aty);
     void readPatternDictSeg(unsigned int segNum, unsigned int length);
     void readHalftoneRegionSeg(unsigned int segNum, bool imm, bool lossless, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs);
     void readGenericRegionSeg(unsigned int segNum, bool imm, bool lossless, unsigned int length);
     void mmrAddPixels(int a1, int blackPixels, int *codingLine, int *a0i, int w);
     void mmrAddPixelsNeg(int a1, int blackPixels, int *codingLine, int *a0i, int w);
-    JBIG2Bitmap *readGenericBitmap(bool mmr, int w, int h, int templ, bool tpgdOn, bool useSkip, JBIG2Bitmap *skip, int *atx, int *aty, int mmrDataLength);
+    std::unique_ptr<JBIG2Bitmap> readGenericBitmap(bool mmr, int w, int h, int templ, bool tpgdOn, bool useSkip, JBIG2Bitmap *skip, int *atx, int *aty, int mmrDataLength);
     void readGenericRefinementRegionSeg(unsigned int segNum, bool imm, bool lossless, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs);
-    JBIG2Bitmap *readGenericRefinementRegion(int w, int h, int templ, bool tpgrOn, JBIG2Bitmap *refBitmap, int refDX, int refDY, int *atx, int *aty);
+    std::unique_ptr<JBIG2Bitmap> readGenericRefinementRegion(int w, int h, int templ, bool tpgrOn, JBIG2Bitmap *refBitmap, int refDX, int refDY, int *atx, int *aty);
     void readPageInfoSeg(unsigned int length);
     void readEndOfStripeSeg(unsigned int length);
     void readProfilesSeg(unsigned int length);
@@ -101,8 +99,8 @@ private:
     unsigned int pageDefPixel;
     JBIG2Bitmap *pageBitmap;
     unsigned int defCombOp;
-    std::vector<JBIG2Segment *> segments;
-    std::vector<JBIG2Segment *> globalSegments;
+    std::vector<std::unique_ptr<JBIG2Segment>> segments;
+    std::vector<std::unique_ptr<JBIG2Segment>> globalSegments;
     Stream *curStr;
     unsigned char *dataPtr;
     unsigned char *dataEnd;


More information about the poppler mailing list