Grok 12.0.1
Namespaces | Macros | Functions | Variables
T1.cpp File Reference
#include <Logger.h>
#include "grk_includes.h"
#include "t1_common.h"
#include "t1_luts.h"

Namespaces

namespace  grk
 Copyright (C) 2016-2024 Grok Image Compression Inc.
 

Macros

#define T1_SIGMA_0   (1U << 0)
 We hold the state of individual data points for the T1 compressor using a single 32-bit flags word to hold the state of 4 data points.
 
#define T1_SIGMA_1   (1U << 1)
 
#define T1_SIGMA_2   (1U << 2)
 
#define T1_SIGMA_3   (1U << 3)
 
#define T1_SIGMA_4   (1U << 4)
 
#define T1_SIGMA_5   (1U << 5)
 
#define T1_SIGMA_6   (1U << 6)
 
#define T1_SIGMA_7   (1U << 7)
 
#define T1_SIGMA_8   (1U << 8)
 
#define T1_SIGMA_9   (1U << 9)
 
#define T1_SIGMA_10   (1U << 10)
 
#define T1_SIGMA_11   (1U << 11)
 
#define T1_SIGMA_12   (1U << 12)
 
#define T1_SIGMA_13   (1U << 13)
 
#define T1_SIGMA_14   (1U << 14)
 
#define T1_SIGMA_15   (1U << 15)
 
#define T1_SIGMA_16   (1U << 16)
 
#define T1_SIGMA_17   (1U << 17)
 
#define T1_CHI_0   (1U << 18)
 
#define T1_CHI_0_I   18
 
#define T1_CHI_1   (1U << 19)
 
#define T1_CHI_1_I   19
 
#define T1_MU_0   (1U << 20)
 
#define T1_PI_0   (1U << 21)
 
#define T1_CHI_2   (1U << 22)
 
#define T1_CHI_2_I   22
 
#define T1_MU_1   (1U << 23)
 
#define T1_PI_1_I   24
 
#define T1_PI_1   (1U << T1_PI_1_I)
 
#define T1_CHI_3   (1U << 25)
 
#define T1_MU_2   (1U << 26)
 
#define T1_PI_2_I   27
 
#define T1_PI_2   (1U << T1_PI_2_I)
 
#define T1_CHI_4   (1U << 28)
 
#define T1_MU_3   (1U << 29)
 
#define T1_PI_3   (1U << 30)
 
#define T1_CHI_5   (1U << 31)
 
#define T1_CHI_5_I   31
 
#define T1_SIGMA_NW   T1_SIGMA_0
 As an example, the bits T1_SIGMA_3, T1_SIGMA_4 and T1_SIGMA_5 indicate the significance state of the west neighbour of data point zero of our four, the point itself, and its east neighbour respectively.
 
#define T1_SIGMA_N   T1_SIGMA_1
 
#define T1_SIGMA_NE   T1_SIGMA_2
 
#define T1_SIGMA_W   T1_SIGMA_3
 
#define T1_SIGMA_THIS   T1_SIGMA_4
 
#define T1_SIGMA_E   T1_SIGMA_5
 
#define T1_SIGMA_SW   T1_SIGMA_6
 
#define T1_SIGMA_S   T1_SIGMA_7
 
#define T1_SIGMA_SE   T1_SIGMA_8
 
#define T1_SIGMA_NEIGHBOURS
 
#define T1_CHI_THIS   T1_CHI_1
 
#define T1_CHI_THIS_I   T1_CHI_1_I
 
#define T1_MU_THIS   T1_MU_0
 
#define T1_PI_THIS   T1_PI_0
 
#define T1_CHI_S   T1_CHI_2
 
#define T1_LUT_SGN_W   (1U << 0)
 
#define T1_LUT_SIG_N   (1U << 1)
 
#define T1_LUT_SGN_E   (1U << 2)
 
#define T1_LUT_SIG_W   (1U << 3)
 
#define T1_LUT_SGN_N   (1U << 4)
 
#define T1_LUT_SIG_E   (1U << 5)
 
#define T1_LUT_SGN_S   (1U << 6)
 
#define T1_LUT_SIG_S   (1U << 7)
 
#define T1_TYPE_MQ   0 /** Normal coding using entropy coder */
 
#define T1_TYPE_RAW   1 /** Raw compressing*/
 
#define setcurctx(curctx, ctxno)   curctx = &(mqc)->ctxs[(uint32_t)(ctxno)]
 
#define update_flags_macro(flags, flagsp, ci, s, stride, vsc)
 
#define enc_sigpass_step_macro(datap, ci, vsc)
 
#define enc_refpass_step_macro(datap, ci)
 
#define dec_clnpass_step_macro(check_flags, partial, flags, flagsp, flags_stride, data, data_stride, ciorig, ci, vsc)
 
#define dec_clnpass_internal(t1, bpno, vsc, w, h, flags_stride)
 
#define dec_sigpass_step_mqc_macro(flags, flagsp, flags_stride, data, data_stride, ciorig, ci, vsc)
 
#define dec_sigpass_mqc_internal(bpno, vsc, w, h, flags_stride)
 
#define dec_refpass_step_mqc_macro(flags, data, data_stride, ciorig, ci)
 
#define dec_refpass_mqc_internal(bpno, w, h, flags_stride)
 

Functions

static INLINE void grk::update_flags (grk_flag *flagsp, uint32_t ci, uint32_t s, uint32_t stride, uint32_t vsc)
 
static int16_t grk::getnmsedec_sig (uint32_t x, uint32_t bitpos)
 
static int16_t grk::getnmsedec_ref (uint32_t x, uint32_t bitpos)
 
static INLINE uint8_t grk::getctxno_zc (mqcoder *mqc, uint32_t f)
 
static INLINE uint8_t grk::getctxno_mag (uint32_t f)
 
static INLINE uint8_t grk::getctxtno_sc_or_spb_index (uint32_t fX, uint32_t pfX, uint32_t nfX, uint32_t ci)
 
static INLINE uint8_t grk::getspb (uint32_t lu)
 
static INLINE uint8_t grk::getctxno_sc (uint32_t lu)
 

Variables

static const double grk::dwt_norms [4][10]
 
static const double grk::dwt_norms_real [4][10]
 

Macro Definition Documentation

◆ dec_clnpass_internal

#define dec_clnpass_internal ( t1,
bpno,
vsc,
w,
h,
flags_stride )

◆ dec_clnpass_step_macro

#define dec_clnpass_step_macro ( check_flags,
partial,
flags,
flagsp,
flags_stride,
data,
data_stride,
ciorig,
ci,
vsc )
Value:
{ \
if(!check_flags || !(flags & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci)))) \
{ \
do \
{ \
uint32_t v; \
if(!partial) \
{ \
uint32_t ctxt1 = getctxno_zc(mqc, flags >> (ci)); \
setcurctx(curctx, ctxt1); \
decompress_macro(v, mqc, curctx, a, c, ct); \
if(!v) \
break; \
} \
uint32_t lu = getctxtno_sc_or_spb_index(flags, flagsp[-1], flagsp[1], ci); \
setcurctx(curctx, getctxno_sc(lu)); \
decompress_macro(v, mqc, curctx, a, c, ct); \
v = v ^ getspb(lu); \
(data)[ciorig * data_stride] = v ? -oneplushalf : oneplushalf; \
update_flags_macro(flags, flagsp, ci, v, flags_stride, vsc); \
} while(0); \
} \
}
#define T1_SIGMA_THIS
Definition T1.cpp:103
#define T1_PI_THIS
Definition T1.cpp:115

◆ dec_refpass_mqc_internal

#define dec_refpass_mqc_internal ( bpno,
w,
h,
flags_stride )

◆ dec_refpass_step_mqc_macro

#define dec_refpass_step_mqc_macro ( flags,
data,
data_stride,
ciorig,
ci )
Value:
{ \
if((flags & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci))) == (T1_SIGMA_THIS << (ci))) \
{ \
uint32_t ctxt = getctxno_mag(flags >> (ci)); \
setcurctx(curctx, ctxt); \
uint32_t v; \
decompress_macro(v, mqc, curctx, a, c, ct); \
(data)[ciorig * data_stride] += \
(v ^ ((data)[ciorig * data_stride] < 0)) ? poshalf : -poshalf; \
flags |= T1_MU_THIS << (ci); \
} \
}
#define T1_MU_THIS
Definition T1.cpp:114

◆ dec_sigpass_mqc_internal

#define dec_sigpass_mqc_internal ( bpno,
vsc,
w,
h,
flags_stride )

◆ dec_sigpass_step_mqc_macro

#define dec_sigpass_step_mqc_macro ( flags,
flagsp,
flags_stride,
data,
data_stride,
ciorig,
ci,
vsc )
Value:
{ \
if((flags & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci))) == 0U && \
(flags & (T1_SIGMA_NEIGHBOURS << (ci))) != 0U) \
{ \
uint32_t ctxt1 = getctxno_zc(mqc, flags >> (ci)); \
setcurctx(curctx, ctxt1); \
uint32_t v; \
decompress_macro(v, mqc, curctx, a, c, ct); \
if(v) \
{ \
uint32_t lu = getctxtno_sc_or_spb_index(flags, flagsp[-1], flagsp[1], ci); \
uint32_t ctxt2 = getctxno_sc(lu); \
uint32_t spb = getspb(lu); \
setcurctx(curctx, ctxt2); \
decompress_macro(v, mqc, curctx, a, c, ct); \
v = v ^ spb; \
(data)[(ciorig)*data_stride] = v ? -oneplushalf : oneplushalf; \
update_flags_macro(flags, flagsp, ci, v, flags_stride, vsc); \
} \
flags |= T1_PI_THIS << (ci); \
} \
}
#define T1_SIGMA_NEIGHBOURS
Definition T1.cpp:108

◆ enc_refpass_step_macro

#define enc_refpass_step_macro ( datap,
ci )
Value:
{ \
uint32_t v; \
uint32_t const shift_flags = (*flagsp >> (ci)); \
if((shift_flags & (T1_SIGMA_THIS | T1_PI_THIS)) == T1_SIGMA_THIS) \
{ \
uint8_t ctxno = getctxno_mag(shift_flags); \
if(nmsedec) \
*nmsedec += getnmsedec_ref((uint32_t)smr_abs(*(datap)), (uint32_t)bpno); \
v = !!(smr_abs(*(datap)) & (uint32_t)one); \
curctx = mqc->ctxs + ctxno; \
if(type == T1_TYPE_RAW) \
mqc_bypass_enc_macro(mqc, c, ct, v) else mqc_encode_macro( \
mqc, curctx, a, c, ct, v)* flagsp |= T1_MU_THIS << (ci); \
} \
}
#define T1_TYPE_RAW
Definition T1.cpp:128
#define mqc_encode_macro(mqc, curctx, a, c, ct, d)
Definition mqc_enc_inl.h:93
#define smr_abs(x)
Definition t1_common.h:85

Referenced by grk::T1::enc_refpass().

◆ enc_sigpass_step_macro

#define enc_sigpass_step_macro ( datap,
ci,
vsc )
Value:
{ \
uint32_t v; \
if((*flagsp & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci))) == 0U && \
(*flagsp & (T1_SIGMA_NEIGHBOURS << (ci))) != 0U) \
{ \
uint8_t ctxno = getctxno_zc(mqc, *flagsp >> (ci)); \
v = !!(smr_abs(*(datap)) & (uint32_t)one); \
curctx = mqc->ctxs + ctxno; \
if(type == T1_TYPE_RAW) \
mqc_bypass_enc_macro(mqc, c, ct, v) else mqc_encode_macro(mqc, curctx, a, c, ct, \
v) if(v) \
{ \
uint32_t lu = getctxtno_sc_or_spb_index(*flagsp, flagsp[-1], flagsp[1], ci); \
ctxno = getctxno_sc(lu); \
v = smr_sign(*(datap)); \
if(nmsedec) \
*nmsedec += getnmsedec_sig((uint32_t)smr_abs(*(datap)), (uint32_t)bpno); \
curctx = mqc->ctxs + ctxno; \
if(type == T1_TYPE_RAW) \
mqc_bypass_enc_macro(mqc, c, ct, v) else mqc_encode_macro(mqc, curctx, a, c, ct, \
v ^ getspb(lu)) \
update_flags(flagsp, ci, v, w + 2, vsc); \
} \
*flagsp |= T1_PI_THIS << (ci); \
} \
}
#define smr_sign(x)
Definition t1_common.h:86

Referenced by grk::T1::enc_sigpass().

◆ setcurctx

#define setcurctx ( curctx,
ctxno )   curctx = &(mqc)->ctxs[(uint32_t)(ctxno)]

◆ T1_CHI_0

#define T1_CHI_0   (1U << 18)

◆ T1_CHI_0_I

#define T1_CHI_0_I   18

◆ T1_CHI_1

#define T1_CHI_1   (1U << 19)

◆ T1_CHI_1_I

#define T1_CHI_1_I   19

◆ T1_CHI_2

#define T1_CHI_2   (1U << 22)

◆ T1_CHI_2_I

#define T1_CHI_2_I   22

◆ T1_CHI_3

#define T1_CHI_3   (1U << 25)

◆ T1_CHI_4

#define T1_CHI_4   (1U << 28)

◆ T1_CHI_5

#define T1_CHI_5   (1U << 31)

◆ T1_CHI_5_I

#define T1_CHI_5_I   31

◆ T1_CHI_S

#define T1_CHI_S   T1_CHI_2

◆ T1_CHI_THIS

#define T1_CHI_THIS   T1_CHI_1

◆ T1_CHI_THIS_I

#define T1_CHI_THIS_I   T1_CHI_1_I

◆ T1_LUT_SGN_E

#define T1_LUT_SGN_E   (1U << 2)

Referenced by t1_init_ctxno_sc(), and t1_init_spb().

◆ T1_LUT_SGN_N

#define T1_LUT_SGN_N   (1U << 4)

Referenced by t1_init_ctxno_sc(), and t1_init_spb().

◆ T1_LUT_SGN_S

#define T1_LUT_SGN_S   (1U << 6)

Referenced by t1_init_ctxno_sc(), and t1_init_spb().

◆ T1_LUT_SGN_W

#define T1_LUT_SGN_W   (1U << 0)

Referenced by t1_init_ctxno_sc(), and t1_init_spb().

◆ T1_LUT_SIG_E

#define T1_LUT_SIG_E   (1U << 5)

Referenced by t1_init_ctxno_sc(), and t1_init_spb().

◆ T1_LUT_SIG_N

#define T1_LUT_SIG_N   (1U << 1)

Referenced by t1_init_ctxno_sc(), and t1_init_spb().

◆ T1_LUT_SIG_S

#define T1_LUT_SIG_S   (1U << 7)

Referenced by t1_init_ctxno_sc(), and t1_init_spb().

◆ T1_LUT_SIG_W

#define T1_LUT_SIG_W   (1U << 3)

Referenced by t1_init_ctxno_sc(), and t1_init_spb().

◆ T1_MU_0

#define T1_MU_0   (1U << 20)

Referenced by grk::getctxno_mag().

◆ T1_MU_1

#define T1_MU_1   (1U << 23)

◆ T1_MU_2

#define T1_MU_2   (1U << 26)

◆ T1_MU_3

#define T1_MU_3   (1U << 29)

◆ T1_MU_THIS

#define T1_MU_THIS   T1_MU_0

◆ T1_PI_0

#define T1_PI_0   (1U << 21)

◆ T1_PI_1

#define T1_PI_1   (1U << T1_PI_1_I)

◆ T1_PI_1_I

#define T1_PI_1_I   24

◆ T1_PI_2

#define T1_PI_2   (1U << T1_PI_2_I)

◆ T1_PI_2_I

#define T1_PI_2_I   27

◆ T1_PI_3

#define T1_PI_3   (1U << 30)

◆ T1_PI_THIS

#define T1_PI_THIS   T1_PI_0

◆ T1_SIGMA_0

#define T1_SIGMA_0   (1U << 0)

We hold the state of individual data points for the T1 compressor using a single 32-bit flags word to hold the state of 4 data points.

This corresponds to the 4-point-high columns that the data is processed in. These #defines declare the layout of a 32-bit flags word.

Referenced by t1_init_ctxno_zc().

◆ T1_SIGMA_1

#define T1_SIGMA_1   (1U << 1)

◆ T1_SIGMA_10

#define T1_SIGMA_10   (1U << 10)

◆ T1_SIGMA_11

#define T1_SIGMA_11   (1U << 11)

◆ T1_SIGMA_12

#define T1_SIGMA_12   (1U << 12)

◆ T1_SIGMA_13

#define T1_SIGMA_13   (1U << 13)

◆ T1_SIGMA_14

#define T1_SIGMA_14   (1U << 14)

◆ T1_SIGMA_15

#define T1_SIGMA_15   (1U << 15)

◆ T1_SIGMA_16

#define T1_SIGMA_16   (1U << 16)

◆ T1_SIGMA_17

#define T1_SIGMA_17   (1U << 17)

◆ T1_SIGMA_2

#define T1_SIGMA_2   (1U << 2)

Referenced by t1_init_ctxno_zc().

◆ T1_SIGMA_3

#define T1_SIGMA_3   (1U << 3)

◆ T1_SIGMA_4

#define T1_SIGMA_4   (1U << 4)

◆ T1_SIGMA_5

#define T1_SIGMA_5   (1U << 5)

◆ T1_SIGMA_6

#define T1_SIGMA_6   (1U << 6)

Referenced by t1_init_ctxno_zc().

◆ T1_SIGMA_7

#define T1_SIGMA_7   (1U << 7)

◆ T1_SIGMA_8

#define T1_SIGMA_8   (1U << 8)

Referenced by t1_init_ctxno_zc().

◆ T1_SIGMA_9

#define T1_SIGMA_9   (1U << 9)

◆ T1_SIGMA_E

#define T1_SIGMA_E   T1_SIGMA_5

◆ T1_SIGMA_N

#define T1_SIGMA_N   T1_SIGMA_1

◆ T1_SIGMA_NE

#define T1_SIGMA_NE   T1_SIGMA_2

◆ T1_SIGMA_NEIGHBOURS

#define T1_SIGMA_NEIGHBOURS
Value:
#define T1_SIGMA_W
Definition T1.cpp:102
#define T1_SIGMA_NE
Definition T1.cpp:101
#define T1_SIGMA_SW
Definition T1.cpp:105
#define T1_SIGMA_NW
As an example, the bits T1_SIGMA_3, T1_SIGMA_4 and T1_SIGMA_5 indicate the significance state of the ...
Definition T1.cpp:99
#define T1_SIGMA_N
Definition T1.cpp:100
#define T1_SIGMA_S
Definition T1.cpp:106
#define T1_SIGMA_SE
Definition T1.cpp:107
#define T1_SIGMA_E
Definition T1.cpp:104

Referenced by grk::T1::dec_sigpass_step_raw(), grk::getctxno_mag(), and grk::getctxno_zc().

◆ T1_SIGMA_NW

#define T1_SIGMA_NW   T1_SIGMA_0

As an example, the bits T1_SIGMA_3, T1_SIGMA_4 and T1_SIGMA_5 indicate the significance state of the west neighbour of data point zero of our four, the point itself, and its east neighbour respectively.

Many of the bits are arranged so that given a flags word, you can look at the values for the data point 0, then shift the flags word right by 3 bits and look at the same bit positions to see the values for data point 1.

The #defines below help a bit with this; say you have a flags word f, you can do things like

(f & T1_SIGMA_THIS)

to see the significance bit of data point 0, then do

((f >> 3) & T1_SIGMA_THIS)

to see the significance bit of data point 1.

◆ T1_SIGMA_S

#define T1_SIGMA_S   T1_SIGMA_7

◆ T1_SIGMA_SE

#define T1_SIGMA_SE   T1_SIGMA_8

◆ T1_SIGMA_SW

#define T1_SIGMA_SW   T1_SIGMA_6

◆ T1_SIGMA_THIS

#define T1_SIGMA_THIS   T1_SIGMA_4

◆ T1_SIGMA_W

#define T1_SIGMA_W   T1_SIGMA_3

◆ T1_TYPE_MQ

#define T1_TYPE_MQ   0 /** Normal coding using entropy coder */

◆ T1_TYPE_RAW

#define T1_TYPE_RAW   1 /** Raw compressing*/

◆ update_flags_macro

#define update_flags_macro ( flags,
flagsp,
ci,
s,
stride,
vsc )
Value:
{ \
/* east */ \
flagsp[-1] |= T1_SIGMA_5 << (ci); \
/* mark target as significant */ \
flags |= ((s << T1_CHI_1_I) | T1_SIGMA_4) << (ci); \
/* west */ \
flagsp[1] |= T1_SIGMA_3 << (ci); \
/* north-west, north, north-east */ \
if(ci == 0U && !(vsc)) \
{ \
auto north = flagsp - (stride); \
*north |= (s << T1_CHI_5_I) | T1_SIGMA_16; \
north[-1] |= T1_SIGMA_17; \
north[1] |= T1_SIGMA_15; \
} \
/* south-west, south, south-east */ \
if(ci == 9U) \
{ \
auto south = flagsp + (stride); \
*south |= (s << T1_CHI_0_I) | T1_SIGMA_1; \
south[-1] |= T1_SIGMA_2; \
south[1] |= T1_SIGMA_0; \
} \
}
#define T1_SIGMA_15
Definition T1.cpp:55
#define T1_SIGMA_16
Definition T1.cpp:56
#define T1_CHI_0_I
Definition T1.cpp:59
#define T1_SIGMA_17
Definition T1.cpp:57
#define T1_CHI_1_I
Definition T1.cpp:61
#define T1_SIGMA_3
Definition T1.cpp:43
#define T1_SIGMA_5
Definition T1.cpp:45
#define T1_SIGMA_4
Definition T1.cpp:44
#define T1_SIGMA_0
We hold the state of individual data points for the T1 compressor using a single 32-bit flags word to...
Definition T1.cpp:40
#define T1_SIGMA_1
Definition T1.cpp:41
#define T1_SIGMA_2
Definition T1.cpp:42
#define T1_CHI_5_I
Definition T1.cpp:77

Referenced by grk::update_flags().