Grok  10.0.3
Namespaces | Macros | Functions | Variables
T1.cpp File Reference
#include "grk_includes.h"
#include "t1_common.h"
#include "logger.h"
#include "t1_luts.h"

Namespaces

 grk
 Copyright (C) 2016-2022 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. More...
 
#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. More...
 
#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 uint32_t grk::getctxno_mag (uint32_t f)
 
static INLINE uint32_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
static INLINE uint8_t getctxno_zc(mqcoder *mqc, uint32_t f)
Definition: T1.cpp:142
static INLINE uint32_t getctxtno_sc_or_spb_index(uint32_t fX, uint32_t pfX, uint32_t nfX, uint32_t ci)
Definition: T1.cpp:146
static INLINE uint8_t getctxno_sc(uint32_t lu)
Definition: T1.cpp:174
static INLINE uint8_t getspb(uint32_t lu)
Definition: T1.cpp:185
const vfloat64m1_t v
Definition: rvv-inl.h:1742

◆ 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
static INLINE uint32_t getctxno_mag(uint32_t f)
Definition: T1.cpp:178

◆ 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) \
{ \
uint32_t ctxt = 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 + ctxt; \
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:84
static int16_t getnmsedec_ref(uint32_t x, uint32_t bitpos)
Definition: T1.cpp:196
#define smr_abs(x)
Definition: t1_common.h:82

◆ enc_sigpass_step_macro

#define enc_sigpass_step_macro (   datap,
  ci,
  vsc 
)
Value:
{ \
uint32_t v; \
uint32_t const flags = *flagsp; \
if((flags & ((T1_SIGMA_THIS | T1_PI_THIS) << (ci))) == 0U && \
(flags & (T1_SIGMA_NEIGHBOURS << (ci))) != 0U) \
{ \
uint32_t ctxt1 = getctxno_zc(mqc, flags >> (ci)); \
v = !!(smr_abs(*(datap)) & (uint32_t)one); \
curctx = mqc->ctxs + ctxt1; \
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); \
uint32_t ctxt2 = getctxno_sc(lu); \
v = smr_sign(*(datap)); \
if(nmsedec) \
*nmsedec += getnmsedec_sig((uint32_t)smr_abs(*(datap)), (uint32_t)bpno); \
curctx = mqc->ctxs + ctxt2; \
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); \
} \
}
static int16_t getnmsedec_sig(uint32_t x, uint32_t bitpos)
Definition: T1.cpp:189
#define smr_sign(x)
Definition: t1_common.h:83

◆ 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)

◆ T1_LUT_SGN_N

#define T1_LUT_SGN_N   (1U << 4)

◆ T1_LUT_SGN_S

#define T1_LUT_SGN_S   (1U << 6)

◆ T1_LUT_SGN_W

#define T1_LUT_SGN_W   (1U << 0)

◆ T1_LUT_SIG_E

#define T1_LUT_SIG_E   (1U << 5)

◆ T1_LUT_SIG_N

#define T1_LUT_SIG_N   (1U << 1)

◆ T1_LUT_SIG_S

#define T1_LUT_SIG_S   (1U << 7)

◆ T1_LUT_SIG_W

#define T1_LUT_SIG_W   (1U << 3)

◆ T1_MU_0

#define T1_MU_0   (1U << 20)

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

◆ 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)

◆ 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)

◆ T1_SIGMA_7

#define T1_SIGMA_7   (1U << 7)

◆ T1_SIGMA_8

#define T1_SIGMA_8   (1U << 8)

◆ 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:
T1_SIGMA_SE)
#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_E
Definition: T1.cpp:104

◆ 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