Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-10 10:23:47

0001 //========================================================================
0002 //
0003 // JBIG2Stream.h
0004 //
0005 // Copyright 2002-2003 Glyph & Cog, LLC
0006 //
0007 //========================================================================
0008 
0009 //========================================================================
0010 //
0011 // Modified under the Poppler project - http://poppler.freedesktop.org
0012 //
0013 // All changes made under the Poppler project to this file are licensed
0014 // under GPL version 2 or later
0015 //
0016 // Copyright (C) 2009 David Benjamin <davidben@mit.edu>
0017 // Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
0018 // Copyright (C) 2015 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
0019 // Copyright (C) 2019-2021 Oliver Sander <oliver.sander@tu-dresden.de>
0020 // Copyright (C) 2019 Volker Krause <vkrause@kde.org>
0021 // Copyright (C) 2019, 2021 Albert Astals Cid <aacid@kde.org>
0022 // Copyright (C) 2019, 2020 Even Rouault <even.rouault@spatialys.com>
0023 //
0024 // To see a description of the changes please see the Changelog file that
0025 // came with your tarball or type make ChangeLog if you are building from git
0026 //
0027 //========================================================================
0028 
0029 #ifndef JBIG2STREAM_H
0030 #define JBIG2STREAM_H
0031 
0032 #include "Object.h"
0033 #include "Stream.h"
0034 
0035 class JBIG2Segment;
0036 class JBIG2Bitmap;
0037 class JArithmeticDecoder;
0038 class JArithmeticDecoderStats;
0039 class JBIG2HuffmanDecoder;
0040 struct JBIG2HuffmanTable;
0041 class JBIG2MMRDecoder;
0042 
0043 //------------------------------------------------------------------------
0044 
0045 class JBIG2Stream : public FilterStream
0046 {
0047 public:
0048     JBIG2Stream(Stream *strA, Object &&globalsStreamA, Object *globalsStreamRefA);
0049     ~JBIG2Stream() override;
0050     StreamKind getKind() const override { return strJBIG2; }
0051     void reset() override;
0052     void close() override;
0053     Goffset getPos() override;
0054     int getChar() override;
0055     int lookChar() override;
0056     GooString *getPSFilter(int psLevel, const char *indent) override;
0057     bool isBinary(bool last = true) const override;
0058     virtual Object *getGlobalsStream() { return &globalsStream; }
0059     virtual Ref getGlobalsStreamRef() { return globalsStreamRef; }
0060 
0061 private:
0062     bool hasGetChars() override { return true; }
0063     int getChars(int nChars, unsigned char *buffer) override;
0064 
0065     void readSegments();
0066     bool readSymbolDictSeg(unsigned int segNum, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs);
0067     void readTextRegionSeg(unsigned int segNum, bool imm, bool lossless, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs);
0068     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,
0069                                                 unsigned int defPixel, unsigned int combOp, unsigned int transposed, unsigned int refCorner, int sOffset, const JBIG2HuffmanTable *huffFSTable, const JBIG2HuffmanTable *huffDSTable,
0070                                                 const JBIG2HuffmanTable *huffDTTable, const JBIG2HuffmanTable *huffRDWTable, const JBIG2HuffmanTable *huffRDHTable, const JBIG2HuffmanTable *huffRDXTable,
0071                                                 const JBIG2HuffmanTable *huffRDYTable, const JBIG2HuffmanTable *huffRSizeTable, unsigned int templ, int *atx, int *aty);
0072     void readPatternDictSeg(unsigned int segNum, unsigned int length);
0073     void readHalftoneRegionSeg(unsigned int segNum, bool imm, bool lossless, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs);
0074     void readGenericRegionSeg(unsigned int segNum, bool imm, bool lossless, unsigned int length);
0075     void mmrAddPixels(int a1, int blackPixels, int *codingLine, int *a0i, int w);
0076     void mmrAddPixelsNeg(int a1, int blackPixels, int *codingLine, int *a0i, int w);
0077     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);
0078     void readGenericRefinementRegionSeg(unsigned int segNum, bool imm, bool lossless, unsigned int length, unsigned int *refSegs, unsigned int nRefSegs);
0079     std::unique_ptr<JBIG2Bitmap> readGenericRefinementRegion(int w, int h, int templ, bool tpgrOn, JBIG2Bitmap *refBitmap, int refDX, int refDY, int *atx, int *aty);
0080     void readPageInfoSeg(unsigned int length);
0081     void readEndOfStripeSeg(unsigned int length);
0082     void readProfilesSeg(unsigned int length);
0083     void readCodeTableSeg(unsigned int segNum, unsigned int length);
0084     void readExtensionSeg(unsigned int length);
0085     JBIG2Segment *findSegment(unsigned int segNum);
0086     void discardSegment(unsigned int segNum);
0087     void resetGenericStats(unsigned int templ, JArithmeticDecoderStats *prevStats);
0088     void resetRefinementStats(unsigned int templ, JArithmeticDecoderStats *prevStats);
0089     bool resetIntStats(int symCodeLen);
0090     bool readUByte(unsigned int *x);
0091     bool readByte(int *x);
0092     bool readUWord(unsigned int *x);
0093     bool readULong(unsigned int *x);
0094     bool readLong(int *x);
0095 
0096     Object globalsStream;
0097     Ref globalsStreamRef;
0098     unsigned int pageW, pageH, curPageH;
0099     unsigned int pageDefPixel;
0100     JBIG2Bitmap *pageBitmap;
0101     unsigned int defCombOp;
0102     std::vector<std::unique_ptr<JBIG2Segment>> segments;
0103     std::vector<std::unique_ptr<JBIG2Segment>> globalSegments;
0104     Stream *curStr;
0105     unsigned char *dataPtr;
0106     unsigned char *dataEnd;
0107     unsigned int byteCounter;
0108 
0109     JArithmeticDecoder *arithDecoder;
0110     JArithmeticDecoderStats *genericRegionStats;
0111     JArithmeticDecoderStats *refinementRegionStats;
0112     JArithmeticDecoderStats *iadhStats;
0113     JArithmeticDecoderStats *iadwStats;
0114     JArithmeticDecoderStats *iaexStats;
0115     JArithmeticDecoderStats *iaaiStats;
0116     JArithmeticDecoderStats *iadtStats;
0117     JArithmeticDecoderStats *iaitStats;
0118     JArithmeticDecoderStats *iafsStats;
0119     JArithmeticDecoderStats *iadsStats;
0120     JArithmeticDecoderStats *iardxStats;
0121     JArithmeticDecoderStats *iardyStats;
0122     JArithmeticDecoderStats *iardwStats;
0123     JArithmeticDecoderStats *iardhStats;
0124     JArithmeticDecoderStats *iariStats;
0125     JArithmeticDecoderStats *iaidStats;
0126     JBIG2HuffmanDecoder *huffDecoder;
0127     JBIG2MMRDecoder *mmrDecoder;
0128 };
0129 
0130 #endif