mq

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NumStates is the number of states in MQ-coder
	NumStates = 47

	// InitialA is the initial interval register value
	InitialA = 0x8000

	// MaxContexts is the maximum number of contexts (JPEG 2000 uses up to 19 contexts for EBCOT)
	MaxContexts = 19

	// MaxDecisions is the maximum decisions per code-block (safety limit)
	MaxDecisions        = 1000000
	MaxRenormIterations = 100 // Max renormalization iterations
)

MQ-Coder constants

Variables

View Source
var (
	ErrInvalidContext = errors.New("invalid context index")
	ErrInvalidState   = errors.New("invalid state index")
	ErrUnexpectedEOF  = errors.New("unexpected end of data")
	ErrMaxDecisions   = errors.New("maximum decisions exceeded")
)

Errors

View Source
var StateTable = [NumStates]State{
	{0x5601, 1, 1, 1},
	{0x3401, 2, 6, 0},
	{0x1801, 3, 9, 0},
	{0x0AC1, 4, 12, 0},
	{0x0521, 5, 29, 0},
	{0x0221, 38, 33, 0},
	{0x5601, 7, 6, 1},
	{0x5401, 8, 14, 0},
	{0x4801, 9, 14, 0},
	{0x3801, 10, 14, 0},
	{0x3001, 11, 17, 0},
	{0x2401, 12, 18, 0},
	{0x1C01, 13, 20, 0},
	{0x1601, 29, 21, 0},
	{0x5601, 15, 14, 1},
	{0x5401, 16, 14, 0},
	{0x5101, 17, 15, 0},
	{0x4801, 18, 16, 0},
	{0x3801, 19, 17, 0},
	{0x3401, 20, 18, 0},
	{0x3001, 21, 19, 0},
	{0x2801, 22, 19, 0},
	{0x2401, 23, 20, 0},
	{0x2201, 24, 21, 0},
	{0x1C01, 25, 22, 0},
	{0x1801, 26, 23, 0},
	{0x1601, 27, 24, 0},
	{0x1401, 28, 25, 0},
	{0x1201, 29, 26, 0},
	{0x1101, 30, 27, 0},
	{0x0AC1, 31, 28, 0},
	{0x09C1, 32, 29, 0},
	{0x08A1, 33, 30, 0},
	{0x0521, 34, 31, 0},
	{0x0441, 35, 32, 0},
	{0x02A1, 36, 33, 0},
	{0x0221, 37, 34, 0},
	{0x0141, 38, 35, 0},
	{0x0111, 39, 36, 0},
	{0x0085, 40, 37, 0},
	{0x0049, 41, 38, 0},
	{0x0025, 42, 39, 0},
	{0x0015, 43, 40, 0},
	{0x0009, 44, 41, 0},
	{0x0005, 45, 42, 0},
	{0x0001, 45, 43, 0},
	{0x5601, 46, 46, 0},
}

StateTable contains the 47 MQ-coder states. Based on JPEG 2000 standard (ITU-T T.800 / ISO/IEC 15444-1)

Functions

This section is empty.

Types

type Context

type Context struct {
	State uint8 // Current state index (0-46)
	MPS   uint8 // Most Probable Symbol (0 or 1)
}

Context represents an MQ-coder context

func NewContext

func NewContext() *Context

NewContext creates a new context with initial state

type Decoder

type Decoder struct {
	// Registers
	A  uint32 // Interval register (16-bit effective)
	C  uint32 // Code register (32-bit, lower 16 bits active)
	CT uint8  // Bit counter
	// contains filtered or unexported fields
}

Decoder represents an MQ-coder decoder

func NewDecoder

func NewDecoder(data []byte) *Decoder

NewDecoder creates a new MQ decoder

func (*Decoder) Decode

func (d *Decoder) Decode(ctx int) (uint8, error)

Decode decodes a single bit using the specified context

func (*Decoder) DecodeRaw

func (d *Decoder) DecodeRaw() (uint8, error)

DecodeRaw decodes a raw (bypass) bit

func (*Decoder) GetContext

func (d *Decoder) GetContext(index int) (*Context, error)

GetContext returns the context at the given index

func (*Decoder) Init

func (d *Decoder) Init() error

Init initializes the MQ decoder This follows the INITDEC procedure from the JPEG 2000 standard

func (*Decoder) MarkerFound

func (d *Decoder) MarkerFound() bool

MarkerFound returns true if a marker was encountered

func (*Decoder) Position

func (d *Decoder) Position() int

Position returns current position in data

func (*Decoder) Reset

func (d *Decoder) Reset()

Reset resets the decoder for a new segment

func (*Decoder) SetContext

func (d *Decoder) SetContext(index int, state, mps uint8) error

SetContext sets the context state and MPS

func (*Decoder) SetData

func (d *Decoder) SetData(data []byte)

SetData sets new data for decoding

type Encoder

type Encoder struct {
	// Registers
	A  uint32 // Interval register
	C  uint32 // Code register
	CT uint8  // Bit counter
	BP int    // Byte pointer

	// State
	BPST int // Start byte pointer
	// contains filtered or unexported fields
}

Encoder represents an MQ-coder encoder

func NewEncoder

func NewEncoder() *Encoder

NewEncoder creates a new MQ encoder

func (*Encoder) Encode

func (e *Encoder) Encode(ctx int, bit uint8)

Encode encodes a single bit using the specified context

func (*Encoder) EncodeRaw

func (e *Encoder) EncodeRaw(bit uint8)

EncodeRaw encodes a raw bit without context modeling

func (*Encoder) Flush

func (e *Encoder) Flush() []byte

Flush flushes the encoder and returns output bytes

func (*Encoder) GetContext

func (e *Encoder) GetContext(index int) (*Context, error)

GetContext returns the context at given index

func (*Encoder) Init

func (e *Encoder) Init()

Init initializes the MQ encoder

func (*Encoder) Reset

func (e *Encoder) Reset()

Reset resets the encoder

func (*Encoder) SetContext

func (e *Encoder) SetContext(index int, state, mps uint8) error

SetContext sets context state and MPS

type State

type State struct {
	Qe     uint16 // Probability estimate (Qe value)
	NMPS   uint8  // Next state for MPS
	NLPS   uint8  // Next state for LPS
	Switch uint8  // 1 if MPS/LPS swap needed after LPS
}

State represents an MQ-coder state

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL