mqc.c File Reference
`#include "opj_includes.h"`
`#include <assert.h>`

## Local static functions

static const opj_mqc_state_t | mqc_states [47 *2]
static void | opj_mqc_setbits (opj_mqc_t *mqc)
| Fill mqc->c with 1's for flushing.
OPJ_UINT32 | opj_mqc_numbytes (opj_mqc_t *mqc)
| Return the number of bytes written/read since initialisation.
void | opj_mqc_init_enc (opj_mqc_t *mqc, OPJ_BYTE *bp)
| Initialize the encoder.
void | opj_mqc_flush (opj_mqc_t *mqc)
| Flush the encoder, so that all remaining data is written.
void | opj_mqc_bypass_init_enc (opj_mqc_t *mqc)
| BYPASS mode switch, initialization operation.
void | opj_mqc_bypass_enc (opj_mqc_t *mqc, OPJ_UINT32 d)
| BYPASS mode switch, coding operation.
OPJ_UINT32 | opj_mqc_bypass_get_extra_bytes (opj_mqc_t *mqc, OPJ_BOOL erterm)
| Return number of extra bytes to add to opj_mqc_numbytes() for the² size of a non-terminating BYPASS pass.
void | opj_mqc_bypass_flush_enc (opj_mqc_t *mqc, OPJ_BOOL erterm)
| BYPASS mode switch, flush operation.
void | opj_mqc_reset_enc (opj_mqc_t *mqc)
| RESET mode switch.
void | opj_mqc_restart_init_enc (opj_mqc_t *mqc)
| RESTART mode switch (TERMALL) reinitialisation.
void | opj_mqc_erterm_enc (opj_mqc_t *mqc)
| ERTERM mode switch (PTERM)
static INLINE void | opj_mqc_renorme (opj_mqc_t *mqc)
static INLINE void | opj_mqc_codemps (opj_mqc_t *mqc)
| Encode the most probable symbol.
static INLINE void | opj_mqc_codelps (opj_mqc_t *mqc)
| Encode the most least symbol.
static INLINE void | opj_mqc_encode (opj_mqc_t *mqc, OPJ_UINT32 d)
| Encode a symbol using the MQ-coder.
void | opj_mqc_segmark_enc (opj_mqc_t *mqc)
| SEGMARK mode switch (SEGSYM)
static void | opj_mqc_init_dec_common (opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len, OPJ_UINT32 extra_writable_bytes)
void | opj_mqc_init_dec (opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len, OPJ_UINT32 extra_writable_bytes)
| Initialize the decoder for MQ decoding.
void | opj_mqc_raw_init_dec (opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len, OPJ_UINT32 extra_writable_bytes)
| Initialize the decoder for RAW decoding.
void | opq_mqc_finish_dec (opj_mqc_t *mqc)
| Terminate RAW/MQC decoding.
void | opj_mqc_resetstates (opj_mqc_t *mqc)
| Reset the states of all the context of the coder/decoder (each context is set to a state where 0 and 1 are more or less equiprobable)
void | opj_mqc_setstate (opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob)
| Set the state of a particular context.
void | opj_mqc_byteout (opj_mqc_t *mqc)
| Output a byte, doing bit-stuffing if necessary.

## Function Documentation

## opj_mqc_bypass_enc()

void opj_mqc_bypass_enc | ( | opj_mqc_t * | mqc,
|  | OPJ_UINT32 | d
| ) |  |

BYPASS mode switch, coding operation.

JPEG 2000 p 505.

Parameters

  mqc | MQC handle
  d | The symbol to be encoded (0 or 1)

References opj_mqc::bp, BYPASS_CT_INIT, opj_mqc::c, and opj_mqc::ct.

## opj_mqc_bypass_flush_enc()

void opj_mqc_bypass_flush_enc | ( | opj_mqc_t * | mqc,
|  | OPJ_BOOL | erterm
| ) |  |

BYPASS mode switch, flush operation.

Parameters

  mqc | MQC handle
  erterm | 1 if ERTERM is enabled, 0 otherwise

References opj_mqc::bp, opj_mqc::c, and opj_mqc::ct.

Referenced by opj_t1_encode_cblk().

## opj_mqc_bypass_get_extra_bytes()

OPJ_UINT32 opj_mqc_bypass_get_extra_bytes | ( | opj_mqc_t * | mqc,
|  | OPJ_BOOL | erterm
| ) |  |

Return number of extra bytes to add to opj_mqc_numbytes() for the² size of a non-terminating BYPASS pass.

Parameters

  mqc | MQC handle
  erterm | 1 if ERTERM is enabled, 0 otherwise

References opj_mqc::bp, and opj_mqc::ct.

Referenced by opj_t1_encode_cblk().

## opj_mqc_bypass_init_enc()

void opj_mqc_bypass_init_enc | ( | opj_mqc_t * | mqc | ) |

BYPASS mode switch, initialization operation.

JPEG 2000 p 505.

Parameters

  mqc | MQC handle

References opj_mqc::bp, BYPASS_CT_INIT, opj_mqc::c, opj_mqc::ct, and opj_mqc::start.

Referenced by opj_t1_encode_cblk().

## opj_mqc_byteout()

void opj_mqc_byteout | ( | opj_mqc_t * | mqc | ) |

Output a byte, doing bit-stuffing if necessary.

After a 0xff byte, the next byte must be smaller than 0x90.

Parameters

  mqc | MQC handle

References opj_mqc::bp, opj_mqc::c, opj_mqc::ct, and opj_mqc::start.

Referenced by opj_mqc_erterm_enc(), and opj_mqc_flush().

## opj_mqc_codelps()

static INLINE void opj_mqc_codelps | ( | opj_mqc_t * | mqc | ) |

static

Encode the most least symbol.

Parameters

  mqc | MQC handle

References opj_mqc::a, opj_mqc::c, opj_mqc::ct, opj_mqc::curctx, and opj_mqc_codelps_macro.

Referenced by opj_mqc_encode().

## opj_mqc_codemps()

static INLINE void opj_mqc_codemps | ( | opj_mqc_t * | mqc | ) |

static

Encode the most probable symbol.

Parameters

  mqc | MQC handle

References opj_mqc::a, opj_mqc::c, opj_mqc::ct, opj_mqc::curctx, and opj_mqc_codemps_macro.

Referenced by opj_mqc_encode().

## opj_mqc_encode()

static INLINE void opj_mqc_encode | ( | opj_mqc_t * | mqc,
|  | OPJ_UINT32 | d
| ) |  |

static

Encode a symbol using the MQ-coder.

Parameters

  mqc | MQC handle
  d | The symbol to be encoded (0 or 1)

References opj_mqc::curctx, opj_mqc_codelps(), and opj_mqc_codemps().

Referenced by opj_mqc_segmark_enc().

## opj_mqc_erterm_enc()

void opj_mqc_erterm_enc | ( | opj_mqc_t * | mqc | ) |

ERTERM mode switch (PTERM)

Parameters

  mqc | MQC handle

References opj_mqc::bp, opj_mqc::c, opj_mqc::ct, and opj_mqc_byteout().

Referenced by opj_t1_encode_cblk().

## opj_mqc_flush()

void opj_mqc_flush | ( | opj_mqc_t * | mqc | ) |

Flush the encoder, so that all remaining data is written.

Parameters

  mqc | MQC handle

References opj_mqc::bp, opj_mqc::c, opj_mqc::ct, opj_mqc_byteout(), and opj_mqc_setbits().

Referenced by opj_t1_encode_cblk().

## opj_mqc_init_dec()

void opj_mqc_init_dec | ( | opj_mqc_t * | mqc,
|  | OPJ_BYTE * | bp,
|  | OPJ_UINT32 | len,
|  | OPJ_UINT32 | extra_writable_bytes
| ) |  |

Initialize the decoder for MQ decoding.

opj_mqc_finish_dec() must be absolutely called after finishing the decoding passes, so as to restore the bytes temporarily overwritten.

Parameters

  mqc | MQC handle
  bp | Pointer to the start of the buffer from which the bytes will be read Note that OPJ_COMMON_CBLK_DATA_EXTRA bytes at the end of the buffer will be temporarily overwritten with an artificial 0xFF 0xFF marker. (they will be backuped in the mqc structure to be restored later) So bp must be at least len + OPJ_COMMON_CBLK_DATA_EXTRA large, and writable.
  len | Length of the input buffer
  extra_writable_bytes | Indicate how many bytes after len are writable. This is to indicate your consent that bp must be large enough.

References opj_mqc::a, opj_mqc::bp, opj_mqc::c, opj_mqc::ct, opj_mqc::end_of_byte_stream_counter, opj_mqc_bytein(), opj_mqc_init_dec_common(), and opj_mqc_setcurctx.

Referenced by opj_t1_decode_cblk().

## opj_mqc_init_dec_common()

static void opj_mqc_init_dec_common | ( | opj_mqc_t * | mqc,
|  | OPJ_BYTE * | bp,
|  | OPJ_UINT32 | len,
|  | OPJ_UINT32 | extra_writable_bytes
| ) |  |

static

References opj_mqc::backup, opj_mqc::bp, opj_mqc::end, OPJ_COMMON_CBLK_DATA_EXTRA, and opj_mqc::start.

Referenced by opj_mqc_init_dec(), and opj_mqc_raw_init_dec().

## opj_mqc_init_enc()

void opj_mqc_init_enc | ( | opj_mqc_t * | mqc,
|  | OPJ_BYTE * | bp
| ) |  |

Initialize the encoder.

Parameters

  mqc | MQC handle
  bp | Pointer to the start of the buffer where the bytes will be written

References opj_mqc::a, opj_mqc::bp, opj_mqc::c, opj_mqc::ct, opj_mqc::end_of_byte_stream_counter, opj_mqc_setcurctx, and opj_mqc::start.

Referenced by opj_t1_encode_cblk().

## opj_mqc_numbytes()

OPJ_UINT32 opj_mqc_numbytes | ( | opj_mqc_t * | mqc | ) |

Return the number of bytes written/read since initialisation.

Parameters

  mqc | MQC handle

Returns
  Returns the number of bytes already encoded

References opj_mqc::bp, and opj_mqc::start.

Referenced by opj_t1_encode_cblk().

## opj_mqc_raw_init_dec()

void opj_mqc_raw_init_dec | ( | opj_mqc_t * | mqc,
|  | OPJ_BYTE * | bp,
|  | OPJ_UINT32 | len,
|  | OPJ_UINT32 | extra_writable_bytes
| ) |  |

Initialize the decoder for RAW decoding.

opj_mqc_finish_dec() must be absolutely called after finishing the decoding passes, so as to restore the bytes temporarily overwritten.

Parameters

  mqc | MQC handle
  bp | Pointer to the start of the buffer from which the bytes will be read Note that OPJ_COMMON_CBLK_DATA_EXTRA bytes at the end of the buffer will be temporarily overwritten with an artificial 0xFF 0xFF marker. (they will be backuped in the mqc structure to be restored later) So bp must be at least len + OPJ_COMMON_CBLK_DATA_EXTRA large, and writable.
  len | Length of the input buffer
  extra_writable_bytes | Indicate how many bytes after len are writable. This is to indicate your consent that bp must be large enough.

References opj_mqc::c, opj_mqc::ct, and opj_mqc_init_dec_common().

Referenced by opj_t1_decode_cblk().

## opj_mqc_renorme()

static INLINE void opj_mqc_renorme | ( | opj_mqc_t * | mqc | ) |

static

References opj_mqc::a, opj_mqc::c, opj_mqc::ct, and opj_mqc_renorme_macro.

## opj_mqc_reset_enc()

void opj_mqc_reset_enc | ( | opj_mqc_t * | mqc | ) |

RESET mode switch.

Parameters

  mqc | MQC handle

References opj_mqc_resetstates(), opj_mqc_setstate(), T1_CTXNO_AGG, T1_CTXNO_UNI, and T1_CTXNO_ZC.

Referenced by opj_t1_encode_cblk().

## opj_mqc_resetstates()

void opj_mqc_resetstates | ( | opj_mqc_t * | mqc | ) |

Reset the states of all the context of the coder/decoder (each context is set to a state where 0 and 1 are more or less equiprobable)

Parameters

  mqc | MQC handle

References opj_mqc::ctxs, MQC_NUMCTXS, and mqc_states.

Referenced by opj_mqc_reset_enc(), opj_t1_decode_cblk(), and opj_t1_encode_cblk().

## opj_mqc_restart_init_enc()

void opj_mqc_restart_init_enc | ( | opj_mqc_t * | mqc | ) |

RESTART mode switch (TERMALL) reinitialisation.

Parameters

  mqc | MQC handle

References opj_mqc::a, opj_mqc::bp, opj_mqc::c, opj_mqc::ct, and opj_mqc::start.

Referenced by opj_t1_encode_cblk().

## opj_mqc_segmark_enc()

void opj_mqc_segmark_enc | ( | opj_mqc_t * | mqc | ) |

SEGMARK mode switch (SEGSYM)

Parameters

  mqc | MQC handle

References opj_mqc_encode(), and opj_mqc_setcurctx.

Referenced by opj_t1_encode_cblk().

## opj_mqc_setbits()

static void opj_mqc_setbits | ( | opj_mqc_t * | mqc | ) |

static

Fill mqc->c with 1's for flushing.

Parameters

  mqc | MQC handle

References opj_mqc::a, and opj_mqc::c.

Referenced by opj_mqc_flush().

## opj_mqc_setstate()

void opj_mqc_setstate | ( | opj_mqc_t * | mqc,
|  | OPJ_UINT32 | ctxno,
|  | OPJ_UINT32 | msb,
|  | OPJ_INT32 | prob
| ) |  |

Set the state of a particular context.

Parameters

  mqc | MQC handle
  ctxno | Number that identifies the context
  msb | The MSB of the new state of the context
  prob | Number that identifies the probability of the symbols for the new state of the context

References opj_mqc::ctxs, and mqc_states.

Referenced by opj_mqc_reset_enc(), opj_t1_decode_cblk(), and opj_t1_encode_cblk().

## opq_mqc_finish_dec()

void opq_mqc_finish_dec | ( | opj_mqc_t * | mqc | ) |

Terminate RAW/MQC decoding.

This restores the bytes temporarily overwritten by opj_mqc_init_dec()/ opj_mqc_raw_init_dec()

Parameters

  mqc | MQC handle

References opj_mqc::backup, opj_mqc::end, and OPJ_COMMON_CBLK_DATA_EXTRA.

Referenced by opj_t1_decode_cblk().

## Variable Documentation

## mqc_states

const opj_mqc_state_t mqc_states[47 *2]

static

Referenced by opj_mqc_resetstates(), and opj_mqc_setstate().