OpenJPEG: MQC - Implementation of an MQ-Coder

OpenJPEG 2.1.2

Data Structures | Macros | Typedefs
MQC - Implementation of an MQ-Coder

## Data Structures
struct | opj_mqc_state
| This struct defines the state of a context. More...
struct | opj_mqc
| MQ coder. More...

## Macros
#define | MQC_NUMCTXS 19

## Typedefs
typedef struct opj_mqc_state | opj_mqc_state_t
| This struct defines the state of a context. More...
typedef struct opj_mqc | opj_mqc_t
| MQ coder. More...

## Local static functions
static void | opj_mqc_byteout (opj_mqc_t *mqc)
| Output a byte, doing bit-stuffing if necessary. More...
static void | opj_mqc_renorme (opj_mqc_t *mqc)
| Renormalize mqc->a and mqc->c while encoding, so that mqc->a stays between 0x8000 and 0x10000. More...
static void | opj_mqc_codemps (opj_mqc_t *mqc)
| Encode the most probable symbol. More...
static void | opj_mqc_codelps (opj_mqc_t *mqc)
| Encode the most least symbol. More...
static void | opj_mqc_setbits (opj_mqc_t *mqc)
| Fill mqc->c with 1's for flushing. More...
static INLINE OPJ_INT32 | opj_mqc_mpsexchange (opj_mqc_t *const mqc)
| FIXME DOC. More...
static INLINE OPJ_INT32 | opj_mqc_lpsexchange (opj_mqc_t *const mqc)
| FIXME DOC. More...
static INLINE void | opj_mqc_bytein (opj_mqc_t *const mqc)
| Input a byte. More...
static INLINE void | opj_mqc_renormd (opj_mqc_t *const mqc)
| Renormalize mqc->a and mqc->c while decoding. More...

## Exported functions
opj_mqc_t * | opj_mqc_create (void)
| Create a new MQC handle. More...
void | opj_mqc_destroy (opj_mqc_t *mqc)
| Destroy a previously created MQC handle. More...
OPJ_UINT32 | opj_mqc_numbytes (opj_mqc_t *mqc)
| Return the number of bytes written/read since initialisation. More...
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) More...
void | opj_mqc_setstate (opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob)
| Set the state of a particular context. More...
void | opj_mqc_init_enc (opj_mqc_t *mqc, OPJ_BYTE *bp)
| Initialize the encoder. More...
void | opj_mqc_encode (opj_mqc_t *mqc, OPJ_UINT32 d)
| Encode a symbol using the MQ-coder. More...
void | opj_mqc_flush (opj_mqc_t *mqc)
| Flush the encoder, so that all remaining data is written. More...
void | opj_mqc_bypass_init_enc (opj_mqc_t *mqc)
| BYPASS mode switch, initialization operation. More...
void | opj_mqc_bypass_enc (opj_mqc_t *mqc, OPJ_UINT32 d)
| BYPASS mode switch, coding operation. More...
OPJ_UINT32 | opj_mqc_bypass_flush_enc (opj_mqc_t *mqc)
| BYPASS mode switch, flush operation. More...
void | opj_mqc_reset_enc (opj_mqc_t *mqc)
| RESET mode switch. More...
OPJ_UINT32 | opj_mqc_restart_enc (opj_mqc_t *mqc)
| RESTART mode switch (TERMALL) More...
void | opj_mqc_restart_init_enc (opj_mqc_t *mqc)
| RESTART mode switch (TERMALL) reinitialisation. More...
void | opj_mqc_erterm_enc (opj_mqc_t *mqc)
| ERTERM mode switch (PTERM) More...
void | opj_mqc_segmark_enc (opj_mqc_t *mqc)
| SEGMARK mode switch (SEGSYM) More...
OPJ_BOOL | opj_mqc_init_dec (opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len)
| Initialize the decoder. More...
OPJ_INT32 | opj_mqc_decode (opj_mqc_t *const mqc)
| Decode a symbol. More...
#define | opj_mqc_setcurctx(mqc, ctxno) (mqc)->curctx = &(mqc)->ctxs[(OPJ_UINT32)(ctxno)]
| Set the current context used for coding/decoding. More...

## Detailed Description

## Macro Definition Documentation

## § MQC_NUMCTXS

#define MQC_NUMCTXS 19

Referenced by opj_mqc_resetstates().

## § opj_mqc_setcurctx

#define opj_mqc_setcurctx | ( |  | mqc,
|  |  | ctxno
| ) |  | (mqc)->curctx = &(mqc)->ctxs[(OPJ_UINT32)(ctxno)]

Set the current context used for coding/decoding.

Parameters

  mqc | MQC handle
  ctxno | Number that identifies the context

Referenced by opj_mqc_init_dec(), opj_mqc_init_enc(), opj_mqc_restart_init_enc(), opj_mqc_segmark_enc(), opj_t1_dec_clnpass(), opj_t1_dec_clnpass_step(), opj_t1_dec_clnpass_step_partial(), opj_t1_dec_clnpass_step_vsc(), opj_t1_dec_refpass_step_mqc(), opj_t1_dec_refpass_step_mqc_vsc(), opj_t1_dec_sigpass_step_mqc(), opj_t1_dec_sigpass_step_mqc_vsc(), opj_t1_enc_clnpass(), opj_t1_enc_clnpass_step(), opj_t1_enc_refpass_step(), opj_t1_enc_sigpass_step(), and opj_t1_encode_cblk().

## Typedef Documentation

## § opj_mqc_state_t

typedef struct opj_mqc_state opj_mqc_state_t

This struct defines the state of a context.

## § opj_mqc_t

typedef struct opj_mqc opj_mqc_t

MQ coder.

## 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.

## Not fully implemented and tested !!

Parameters

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

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

Referenced by opj_t1_enc_refpass_step(), and opj_t1_enc_sigpass_step().

## § opj_mqc_bypass_flush_enc()

OPJ_UINT32 opj_mqc_bypass_flush_enc | ( | opj_mqc_t * | mqc | ) |

BYPASS mode switch, flush operation.

## Not fully implemented and tested !!

Parameters

  mqc | MQC handle

Returns
  Returns 1 (always)

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

## § opj_mqc_bypass_init_enc()

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

BYPASS mode switch, initialization operation.

JPEG 2000 p 505.

## Not fully implemented and tested !!

Parameters

  mqc | MQC handle

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

Referenced by opj_t1_encode_cblk().

## § opj_mqc_bytein()

static void opj_mqc_bytein | ( | opj_mqc_t *const | mqc | ) |
| static

Input a byte.

Parameters

  mqc | MQC handle

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

Referenced by opj_mqc_init_dec(), opj_mqc_lpsexchange(), and opj_mqc_renormd().

## § opj_mqc_byteout()

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

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(), opj_mqc_flush(), opj_mqc_renorme(), and opj_mqc_restart_enc().

## § opj_mqc_codelps()

static 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::curctx, and opj_mqc_renorme().

Referenced by opj_mqc_encode().

## § opj_mqc_codemps()

static 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::curctx, and opj_mqc_renorme().

Referenced by opj_mqc_encode().

## § opj_mqc_create()

opj_mqc_t* opj_mqc_create | ( | void |  | ) |

Create a new MQC handle.

Returns
  Returns a new MQC handle if successful, returns NULL otherwise

References opj_malloc().

Referenced by opj_t1_create().

## § opj_mqc_decode()

OPJ_INT32 opj_mqc_decode | ( | opj_mqc_t *const | mqc | ) |

Decode a symbol.

Parameters

  mqc | MQC handle

Returns
  Returns the decoded symbol (0 or 1)

References opj_mqc::a, opj_mqc::c, opj_mqc::curctx, opj_mqc_lpsexchange(), opj_mqc_mpsexchange(), and opj_mqc_renormd().

Referenced by opj_t1_dec_clnpass(), opj_t1_dec_clnpass_step(), opj_t1_dec_clnpass_step_partial(), opj_t1_dec_clnpass_step_vsc(), opj_t1_dec_refpass_step_mqc(), opj_t1_dec_refpass_step_mqc_vsc(), opj_t1_dec_sigpass_step_mqc(), opj_t1_dec_sigpass_step_mqc_vsc(), and opj_t1_encode_cblk().

## § opj_mqc_destroy()

void opj_mqc_destroy | ( | opj_mqc_t * | mqc | ) |

Destroy a previously created MQC handle.

Parameters

  mqc | MQC handle to destroy

References opj_free().

Referenced by opj_t1_destroy().

## § opj_mqc_encode()

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

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_t1_enc_clnpass(), opj_t1_enc_clnpass_step(), opj_t1_enc_refpass_step(), and opj_t1_enc_sigpass_step().

## § 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()

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

Initialize the decoder.

Parameters

  mqc | MQC handle
  bp | Pointer to the start of the buffer from which the bytes will be read
  len | Length of the input buffer

References opj_mqc::a, opj_mqc::bp, opj_mqc::c, opj_mqc::ct, opj_mqc::end, OPJ_FALSE, opj_free(), opj_mqc_bytein(), opj_mqc_setcurctx, opj_realloc(), OPJ_TRUE, and opj_mqc::start.

Referenced by opj_t1_decode_cblk().

## § 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_setcurctx, and opj_mqc::start.

Referenced by opj_t1_encode_cblk().

## § opj_mqc_lpsexchange()

static INLINE OPJ_INT32 opj_mqc_lpsexchange | ( | opj_mqc_t *const | mqc | ) |
| static

FIXME DOC.

Parameters

  mqc | MQC handle

Returns

References opj_mqc::a, opj_mqc::bp, opj_mqc::c, opj_mqc::ct, opj_mqc::curctx, INLINE, and opj_mqc_bytein().

Referenced by opj_mqc_decode().

## § opj_mqc_mpsexchange()

static INLINE OPJ_INT32 opj_mqc_mpsexchange | ( | opj_mqc_t *const | mqc | ) |
| static

FIXME DOC.

Parameters

  mqc | MQC handle

Returns

References opj_mqc::a, opj_mqc::curctx, and opj_mqc_state::mps.

Referenced by opj_mqc_decode().

## § 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_renormd()

static INLINE void opj_mqc_renormd | ( | opj_mqc_t *const | mqc | ) |
| static

Renormalize mqc->a and mqc->c while decoding.

Parameters

  mqc | MQC handle

References opj_mqc::a, opj_mqc::c, opj_mqc::ct, and opj_mqc_bytein().

Referenced by opj_mqc_decode().

## § opj_mqc_renorme()

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

Renormalize mqc->a and mqc->c while encoding, so that mqc->a stays between 0x8000 and 0x10000.

Parameters

  mqc | MQC handle

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

Referenced by opj_mqc_codelps(), and opj_mqc_codemps().

## § 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_enc()

OPJ_UINT32 opj_mqc_restart_enc | ( | opj_mqc_t * | mqc | ) |

RESTART mode switch (TERMALL)

Parameters

  mqc | MQC handle

Returns
  Returns 1 (always)

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

## § 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_setcurctx.

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.

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