Coverage Report

Created: 2026-02-04 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xpdf-4.06/xpdf/JArithmeticDecoder.h
Line
Count
Source
1
//========================================================================
2
//
3
// JArithmeticDecoder.h
4
//
5
// Arithmetic decoder used by the JBIG2 and JPEG2000 decoders.
6
//
7
// Copyright 2002-2004 Glyph & Cog, LLC
8
//
9
//========================================================================
10
11
#ifndef JARITHMETICDECODER_H
12
#define JARITHMETICDECODER_H
13
14
#include <aconf.h>
15
16
#include "gtypes.h"
17
18
class Stream;
19
20
//------------------------------------------------------------------------
21
// JArithmeticDecoderStats
22
//------------------------------------------------------------------------
23
24
class JArithmeticDecoderStats {
25
public:
26
27
  JArithmeticDecoderStats(int contextSizeA);
28
  ~JArithmeticDecoderStats();
29
  JArithmeticDecoderStats *copy();
30
  void reset();
31
27.7k
  int getContextSize() { return contextSize; }
32
  void copyFrom(JArithmeticDecoderStats *stats);
33
  void setEntry(Guint cx, int i, int mps);
34
35
private:
36
37
  Guchar *cxTab;    // cxTab[cx] = (i[cx] << 1) + mps[cx]
38
  int contextSize;
39
40
  friend class JArithmeticDecoder;
41
};
42
43
//------------------------------------------------------------------------
44
// JArithmeticDecoder
45
//------------------------------------------------------------------------
46
47
class JArithmeticDecoder {
48
public:
49
50
  JArithmeticDecoder();
51
  ~JArithmeticDecoder();
52
53
  void setStream(Stream *strA)
54
164k
    { str = strA; dataLen = 0; limitStream = gFalse; }
55
  void setStream(Stream *strA, int dataLenA)
56
864k
    { str = strA; dataLen = dataLenA; limitStream = gTrue; }
57
58
  // Start decoding on a new stream.  This fills the byte buffers and
59
  // runs INITDEC.
60
  void start();
61
62
  // Restart decoding on an interrupted stream.  This refills the
63
  // buffers if needed, but does not run INITDEC.  (This is used in
64
  // JPEG 2000 streams when codeblock data is split across multiple
65
  // packets/layers.)
66
  void restart(int dataLenA);
67
68
  // Read any leftover data in the stream.
69
  void cleanup();
70
71
  // Decode one bit.
72
  int decodeBit(Guint context, JArithmeticDecoderStats *stats);
73
74
  // Decode eight bits.
75
  int decodeByte(Guint context, JArithmeticDecoderStats *stats);
76
77
  // Returns false for OOB, otherwise sets *<x> and returns true.
78
  GBool decodeInt(int *x, JArithmeticDecoderStats *stats);
79
80
  Guint decodeIAID(Guint codeLen,
81
       JArithmeticDecoderStats *stats);
82
83
267k
  void resetByteCounter() { nBytesRead = 0; }
84
220k
  Guint getByteCounter() { return nBytesRead; }
85
86
private:
87
88
  Guint readByte();
89
  int decodeIntBit(JArithmeticDecoderStats *stats);
90
  void byteIn();
91
92
  static Guint qeTab[47];
93
  static int nmpsTab[47];
94
  static int nlpsTab[47];
95
  static int switchTab[47];
96
97
  Guint buf0, buf1;
98
  Guint c, a;
99
  int ct;
100
101
  Guint prev;     // for the integer decoder
102
103
  Stream *str;
104
  Guint nBytesRead;
105
  int dataLen;
106
  GBool limitStream;
107
  Guchar readBuf[32];
108
  int readBufNext;
109
  int readBufLength;
110
};
111
112
#endif