Class CX

java.lang.Object
org.apache.pdfbox.jbig2.decoder.arithmetic.CX

public final class CX extends Object
Arithmetic coding context used during JBIG2 bitstream decoding.

Represents a context in the arithmetic decoder that selects probability estimates and statistics used during decoding procedures, as defined in ITU-T Rec. T.88 (2000 E), ISO/IEC 14492:2001.

Context State:

  • cx array: Stores the probability estimate index (0-127) for each context state
  • mps array: Stores the most probable symbol (0 or 1) for each context state
  • index: Current context index, selected based on the neighborhood pattern (template-specific arrangement of previously decoded pixels)

Usage: The index is set before each decision to select which context state to use. After decoding, the arithmetic decoder updates the selected context's probability estimate and MPS based on the decoded symbol (see Annex A, T.88).

Reuse: When arithmetic coding contexts are retained and reused across segments (§7.4.2.2), a copy() must be created to avoid sharing mutable probability state between decoders.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final byte[]
     
    private int
     
    private final byte[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    CX(int size, int index)
    Creates a new context with the specified number of context states.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates and returns a deep copy of this CX object.
    (package private) int
    cx()
     
    (package private) int
     
    (package private) byte
    mps()
     
    (package private) void
    setCx(int value)
     
    void
    setIndex(int index)
    Sets the context index used for subsequent decoding decisions.
    (package private) void
    Flips the bit in actual "more predictable symbol" array element.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • index

      private int index
    • cx

      private final byte[] cx
    • mps

      private final byte[] mps
  • Constructor Details

    • CX

      public CX(int size, int index)
      Creates a new context with the specified number of context states. All probability estimates are initialized to 0, and all MPS values are initialized to 0.
      Parameters:
      size - the number of context states
      index - the initial context index
  • Method Details

    • cx

      int cx()
    • setCx

      void setCx(int value)
    • mps

      byte mps()
      Returns:
      The decision. Possible values are 0 or 1.
    • toggleMps

      void toggleMps()
      Flips the bit in actual "more predictable symbol" array element.
    • getIndex

      int getIndex()
    • setIndex

      public void setIndex(int index)
      Sets the context index used for subsequent decoding decisions. The index selects which context state's probability estimate and MPS will be used.

      The index value is typically computed from the neighboring pixels in the template (§6.2.5.1 for generic regions, §6.4.7.1 for text regions).

      Parameters:
      index - the context index (0 to size-1)
    • copy

      public CX copy()
      Creates and returns a deep copy of this CX object. The new instance will have the same context values, probability estimates, and current index as this object, but will be a separate instance. Changes to the copied object will not affect the original, and vice versa.

      This is required when reusing arithmetic coding contexts across segments, to avoid sharing mutable probability state between decoders.

      Returns:
      A new CX object with the same internal state as this object.