Grok  9.5.0
Classes | Functions | Variables
ojph::local2 Namespace Reference

Classes

struct  dec_mel_st
 MEL state structure for reading and decoding the MEL bitstream. More...
 
struct  rev_struct
 A structure for reading and unstuffing a segment that grows backward, such as VLC and MRP. More...
 
struct  frwd_struct
 State structure for reading and unstuffing of forward-growing bitstreams; these are: MagSgn and SPP bitstreams. More...
 

Functions

bool ojph_decode_codeblock2 (ui8 *coded_data, ui32 *decoded_data, ui32 missing_msbs, ui32 num_passes, ui32 lengths1, ui32 lengths2, ui32 width, ui32 height, ui32 stride)
 Decodes one codeblock, processing the cleanup, siginificance propagation, and magnitude refinement pass. More...
 
static void mel_read (dec_mel_st *melp)
 Reads and unstuffs the MEL bitstream. More...
 
static void mel_decode (dec_mel_st *melp)
 Decodes unstuffed MEL segment bits stored in tmp to runs. More...
 
static void mel_init (dec_mel_st *melp, ui8 *bbuf, int lcup, int scup)
 Initiates a dec_mel_st structure for MEL decoding and reads some bytes in order to get the read address to a multiple of 4. More...
 
static int mel_get_run (dec_mel_st *melp)
 Retrieves one run from dec_mel_st; if there are no runs stored MEL segment is decoded. More...
 
void rev_read (rev_struct *vlcp)
 Read and unstuff data from a backwardly-growing segment. More...
 
void rev_init (rev_struct *vlcp, ui8 *data, int lcup, int scup)
 Initiates the rev_struct structure and reads a few bytes to move the read address to multiple of 4. More...
 
ui32 rev_fetch (rev_struct *vlcp)
 Retrieves 32 bits from the head of a rev_struct structure. More...
 
ui32 rev_advance (rev_struct *vlcp, ui32 num_bits)
 Consumes num_bits from a rev_struct structure. More...
 
void rev_read_mrp (rev_struct *mrp)
 Reads and unstuffs from rev_struct. More...
 
void rev_init_mrp (rev_struct *mrp, ui8 *data, int lcup, int len2)
 Initialized rev_struct structure for MRP segment, and reads a number of bytes such that the next 32 bits read are from an address that is a multiple of 4. More...
 
ui32 rev_fetch_mrp (rev_struct *mrp)
 Retrieves 32 bits from the head of a rev_struct structure. More...
 
ui32 rev_advance_mrp (rev_struct *mrp, ui32 num_bits)
 Consumes num_bits from a rev_struct structure. More...
 
static bool vlc_init_tables ()
 Initializes vlc_tbl0 and vlc_tbl1 tables, from table0.h and table1.h. More...
 
static bool uvlc_init_tables ()
 Initializes uvlc_tbl0 and uvlc_tbl1 tables. More...
 
template<int X>
void frwd_read (frwd_struct *msp)
 Read and unstuffs 32 bits from forward-growing bitstream. More...
 
template<int X>
void frwd_init (frwd_struct *msp, const ui8 *data, int size)
 Initialize frwd_struct struct and reads some bytes. More...
 
void frwd_advance (frwd_struct *msp, ui32 num_bits)
 Consume num_bits bits from the bitstream of frwd_struct. More...
 
template<int X>
__m128i frwd_fetch (frwd_struct *msp)
 Fetches 32 bits from the frwd_struct bitstream. More...
 
template<int N>
static void one_quad_decode (const __m128i &inf_u_q, const __m128i &U_q, frwd_struct *magsgn, ui32 p, int &e0, int &e1, __m128i &row)
 

Variables

static ui16 vlc_tbl0 [1024] = { 0 }
 vlc_tbl0 contains decoding information for initial row of quads More...
 
static ui16 vlc_tbl1 [1024] = { 0 }
 vlc_tbl1 contains decoding information for non-initial row of quads More...
 
static ui16 uvlc_tbl0 [256+64] = { 0 }
 uvlc_tbl0 contains decoding information for initial row of quads More...
 
static ui16 uvlc_tbl1 [256] = { 0 }
 uvlc_tbl1 contains decoding information for non-initial row of quads More...
 
static bool vlc_tables_initialized = vlc_init_tables()
 Initializes VLC tables vlc_tbl0 and vlc_tbl1. More...
 
static bool uvlc_tables_initialized = uvlc_init_tables()
 Initializes UVLC tables uvlc_tbl0 and uvlc_tbl1. More...
 

Function Documentation

◆ frwd_advance()

void ojph::local2::frwd_advance ( frwd_struct msp,
ui32  num_bits 
)
inline

Consume num_bits bits from the bitstream of frwd_struct.

Parameters
[in]mspis a pointer to frwd_struct
[in]num_bitsis the number of bit to consume

References ojph::local2::frwd_struct::bits, and ojph::local2::frwd_struct::tmp.

Referenced by one_quad_decode().

◆ frwd_fetch()

template<int X>
__m128i ojph::local2::frwd_fetch ( frwd_struct msp)

Fetches 32 bits from the frwd_struct bitstream.

Template Parameters
Xis the value fed in when the bitstream is exhausted. See frwd_read regarding the template
Parameters
[in]mspis a pointer to frwd_struct

References ojph::local2::frwd_struct::bits, and ojph::local2::frwd_struct::tmp.

◆ frwd_init()

template<int X>
void ojph::local2::frwd_init ( frwd_struct msp,
const ui8 data,
int  size 
)

Initialize frwd_struct struct and reads some bytes.

Template Parameters
Xis the value fed in when the bitstream is exhausted. See frwd_read regarding the template
Parameters
[in]mspis a pointer to frwd_struct
[in]datais a pointer to the start of data
[in]sizeis the number of byte in the bitstream

References ojph::local2::frwd_struct::bits, ojph::local2::frwd_struct::data, ojph::local2::frwd_struct::size, ojph::local2::frwd_struct::tmp, and ojph::local2::frwd_struct::unstuff.

◆ frwd_read()

template<int X>
void ojph::local2::frwd_read ( frwd_struct msp)

Read and unstuffs 32 bits from forward-growing bitstream.

A template is used to accommodate a different requirement for MagSgn and SPP bitstreams; in particular, when MagSgn bitstream is consumed, 0xFF's are fed, while when SPP is exhausted 0's are fed in. X controls this value.

Unstuffing prevent sequences that are more than 0xFF7F from appearing in the conpressed sequence. So whenever a value of 0xFF is coded, the MSB of the next byte is set 0 and must be ignored during decoding.

Reading can go beyond the end of buffer by up to 16 bytes.

Template Parameters
Xis the value fed in when the bitstream is exhausted
Parameters
[in]mspis a pointer to frwd_struct structure

References ojph::local2::frwd_struct::bits, ojph::count_leading_zeros(), ojph::local2::frwd_struct::data, ojph::local2::frwd_struct::size, ojph::local2::frwd_struct::tmp, and ojph::local2::frwd_struct::unstuff.

◆ mel_decode()

static void ojph::local2::mel_decode ( dec_mel_st melp)
inlinestatic

Decodes unstuffed MEL segment bits stored in tmp to runs.

Runs are stored in "runs" and the number of runs in "num_runs". Each run represents a number of zero events that may or may not terminate in a 1 event. Each run is stored in 7 bits. The LSB is 1 if the run terminates in a 1 event, 0 otherwise. The next 6 bits, for the case terminating with 1, contain the number of consecutive 0 zero events * 2; for the case terminating with 0, they store (number of consecutive 0 zero events - 1) * 2. A total of 6 bits (made up of 1 + 5) should have been enough.

Parameters
[in]melpis a pointer to dec_mel_st structure

References ojph::local2::dec_mel_st::bits, ojph::local2::dec_mel_st::k, mel_read(), ojph::local2::dec_mel_st::num_runs, ojph::local2::dec_mel_st::runs, and ojph::local2::dec_mel_st::tmp.

Referenced by mel_get_run().

◆ mel_get_run()

static int ojph::local2::mel_get_run ( dec_mel_st melp)
inlinestatic

Retrieves one run from dec_mel_st; if there are no runs stored MEL segment is decoded.

Parameters
[in]melpis a pointer to dec_mel_st structure

References mel_decode(), ojph::local2::dec_mel_st::num_runs, and ojph::local2::dec_mel_st::runs.

Referenced by ojph_decode_codeblock2().

◆ mel_init()

static void ojph::local2::mel_init ( dec_mel_st melp,
ui8 bbuf,
int  lcup,
int  scup 
)
inlinestatic

Initiates a dec_mel_st structure for MEL decoding and reads some bytes in order to get the read address to a multiple of 4.

Parameters
[in]melpis a pointer to dec_mel_st structure
[in]bbufis a pointer to byte buffer
[in]lcupis the length of MagSgn+MEL+VLC segments
[in]scupis the length of MEL+VLC segments

References ojph::local2::dec_mel_st::bits, ojph::local2::dec_mel_st::data, ojph::local2::dec_mel_st::k, ojph::local2::dec_mel_st::num_runs, ojph::local2::dec_mel_st::runs, ojph::local2::dec_mel_st::size, ojph::local2::dec_mel_st::tmp, and ojph::local2::dec_mel_st::unstuff.

Referenced by ojph_decode_codeblock2().

◆ mel_read()

static void ojph::local2::mel_read ( dec_mel_st melp)
inlinestatic

Reads and unstuffs the MEL bitstream.

This design needs more bytes in the codeblock buffer than the length of the cleanup pass by up to 2 bytes.

Unstuffing removes the MSB of the byte following a byte whose value is 0xFF; this prevents sequences larger than 0xFF7F in value from appearing the bitstream.

Parameters
[in]melpis a pointer to dec_mel_st structure

References ojph::local2::dec_mel_st::bits, ojph::local2::dec_mel_st::data, ojph::local2::dec_mel_st::size, ojph::local2::dec_mel_st::tmp, and ojph::local2::dec_mel_st::unstuff.

Referenced by mel_decode().

◆ ojph_decode_codeblock2()

bool ojph::local2::ojph_decode_codeblock2 ( ui8 coded_data,
ui32 decoded_data,
ui32  missing_msbs,
ui32  num_passes,
ui32  lengths1,
ui32  lengths2,
ui32  width,
ui32  height,
ui32  stride 
)

Decodes one codeblock, processing the cleanup, siginificance propagation, and magnitude refinement pass.

Parameters
[in]coded_datais a pointer to bitstream
[in]decoded_datais a pointer to decoded codeblock data buf.
[in]missing_msbsis the number of missing MSBs
[in]num_passesis the number of passes: 1 if CUP only, 2 for CUP+SPP, and 3 for CUP+SPP+MRP
[in]lengths1is the length of cleanup pass
[in]lengths2is the length of refinement passes (either SPP only or SPP+MRP)
[in]widthis the decoded codeblock width
[in]heightis the decoded codeblock height
[in]strideis the decoded codeblock buffer stride

References ojph::count_leading_zeros(), grk::gamma, mel_get_run(), mel_init(), OJPH_ERROR, OJPH_WARN, rev_advance(), rev_fetch(), rev_init(), uvlc_tbl0, uvlc_tbl1, vlc_tbl0, and vlc_tbl1.

◆ one_quad_decode()

template<int N>
static void ojph::local2::one_quad_decode ( const __m128i &  inf_u_q,
const __m128i &  U_q,
frwd_struct magsgn,
ui32  p,
int &  e0,
int &  e1,
__m128i &  row 
)
inlinestatic

References frwd_advance(), and grk::shift.

◆ rev_advance()

ui32 ojph::local2::rev_advance ( rev_struct vlcp,
ui32  num_bits 
)
inline

Consumes num_bits from a rev_struct structure.

Parameters
[in]vlcpis a pointer to rev_struct structure
[in]num_bitsis the number of bits to be removed

References ojph::local2::rev_struct::bits, and ojph::local2::rev_struct::tmp.

Referenced by ojph_decode_codeblock2().

◆ rev_advance_mrp()

ui32 ojph::local2::rev_advance_mrp ( rev_struct mrp,
ui32  num_bits 
)
inline

Consumes num_bits from a rev_struct structure.

Parameters
[in]mrpis a pointer to rev_struct structure
[in]num_bitsis the number of bits to be removed

References ojph::local2::rev_struct::bits, and ojph::local2::rev_struct::tmp.

◆ rev_fetch()

ui32 ojph::local2::rev_fetch ( rev_struct vlcp)
inline

Retrieves 32 bits from the head of a rev_struct structure.

By the end of this call, vlcp->tmp must have no less than 33 bits

Parameters
[in]vlcpis a pointer to rev_struct structure

References ojph::local2::rev_struct::bits, rev_read(), and ojph::local2::rev_struct::tmp.

Referenced by ojph_decode_codeblock2().

◆ rev_fetch_mrp()

ui32 ojph::local2::rev_fetch_mrp ( rev_struct mrp)
inline

Retrieves 32 bits from the head of a rev_struct structure.

By the end of this call, mrp->tmp must have no less than 33 bits

Parameters
[in]mrpis a pointer to rev_struct structure

References ojph::local2::rev_struct::bits, rev_read_mrp(), and ojph::local2::rev_struct::tmp.

◆ rev_init()

void ojph::local2::rev_init ( rev_struct vlcp,
ui8 data,
int  lcup,
int  scup 
)
inline

Initiates the rev_struct structure and reads a few bytes to move the read address to multiple of 4.

There is another similar rev_init_mrp subroutine. The difference is that this one, rev_init, discards the first 12 bits (they have the sum of the lengths of VLC and MEL segments), and first unstuff depends on first 4 bits.

Parameters
[in]vlcpis a pointer to rev_struct structure
[in]datais a pointer to byte at the start of the cleanup pass
[in]lcupis the length of MagSgn+MEL+VLC segments
[in]scupis the length of MEL+VLC segments

References ojph::local2::rev_struct::bits, ojph::local2::rev_struct::data, rev_read(), ojph::local2::rev_struct::size, ojph::local2::rev_struct::tmp, and ojph::local2::rev_struct::unstuff.

Referenced by ojph_decode_codeblock2().

◆ rev_init_mrp()

void ojph::local2::rev_init_mrp ( rev_struct mrp,
ui8 data,
int  lcup,
int  len2 
)
inline

Initialized rev_struct structure for MRP segment, and reads a number of bytes such that the next 32 bits read are from an address that is a multiple of 4.

Note this is designed for an architecture that read size must be compatible with the alignment of the read address

There is another simiar subroutine rev_init. This subroutine does NOT skip the first 12 bits, and starts with unstuff set to true.

Parameters
[in]mrpis a pointer to rev_struct structure
[in]datais a pointer to byte at the start of the cleanup pass
[in]lcupis the length of MagSgn+MEL+VLC segments
[in]len2is the length of SPP+MRP segments

References ojph::local2::rev_struct::bits, ojph::local2::rev_struct::data, rev_read_mrp(), ojph::local2::rev_struct::size, ojph::local2::rev_struct::tmp, and ojph::local2::rev_struct::unstuff.

◆ rev_read()

void ojph::local2::rev_read ( rev_struct vlcp)
inline

Read and unstuff data from a backwardly-growing segment.

This reader can read up to 8 bytes from before the VLC segment. Care must be taken not read from unreadable memory, causing a segmentation fault.

Note that there is another subroutine rev_read_mrp that is slightly different. The other one fills zeros when the buffer is exhausted. This one basically does not care if the bytes are consumed, because any extra data should not be used in the actual decoding.

Unstuffing is needed to prevent sequences more than 0xFF8F from appearing in the bits stream; since we are reading backward, we keep watch when a value larger than 0x8F appears in the bitstream. If the byte following this is 0x7F, we unstuff this byte (ignore the MSB of that byte, which should be 0).

Parameters
[in]vlcpis a pointer to rev_struct structure

References ojph::local2::rev_struct::bits, ojph::local2::rev_struct::data, ojph::local2::rev_struct::size, ojph::local2::rev_struct::tmp, and ojph::local2::rev_struct::unstuff.

Referenced by rev_fetch(), and rev_init().

◆ rev_read_mrp()

void ojph::local2::rev_read_mrp ( rev_struct mrp)
inline

Reads and unstuffs from rev_struct.

This is different than rev_read in that this fills in zeros when the the available data is consumed. The other does not care about the values when all data is consumed.

See rev_read for more information about unstuffing

Parameters
[in]mrpis a pointer to rev_struct structure

References ojph::local2::rev_struct::bits, ojph::local2::rev_struct::data, ojph::local2::rev_struct::size, ojph::local2::rev_struct::tmp, and ojph::local2::rev_struct::unstuff.

Referenced by rev_fetch_mrp(), and rev_init_mrp().