Grok  7.6.0
t1.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2020 Grok Image Compression Inc.
3  *
4  * This source code is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License, version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This source code is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Affero General Public License for more details.
12  *
13  * You should have received a copy of the GNU Affero General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  *
17  * This source code incorporates work covered by the BSD 2-clause license.
18  * Please see the LICENSE file in the root directory for details.
19  *
20  */
21 
22 #pragma once
23 
24 #include "t1_flags.h"
25 
26 namespace grk {
27 
28 #define T1_NUMCTXS_ZC 9
29 #define T1_NUMCTXS_SC 5
30 #define T1_NUMCTXS_MAG 3
31 #define T1_NUMCTXS_AGG 1
32 #define T1_NUMCTXS_UNI 1
33 
34 #define T1_CTXNO_ZC 0
35 #define T1_CTXNO_SC (T1_CTXNO_ZC+T1_NUMCTXS_ZC)
36 #define T1_CTXNO_MAG (T1_CTXNO_SC+T1_NUMCTXS_SC)
37 #define T1_CTXNO_AGG (T1_CTXNO_MAG+T1_NUMCTXS_MAG)
38 #define T1_CTXNO_UNI (T1_CTXNO_AGG+T1_NUMCTXS_AGG)
39 #define T1_NUMCTXS (T1_CTXNO_UNI+T1_NUMCTXS_UNI)
40 
41 
43 typedef uint32_t grk_flag;
44 
45 
46 /* BEGINNING of flags that apply to grk_flag */
58 /* SIGMA: significance state (3 cols x 6 rows)
59  * CHI: state for negative sample value (1 col x 6 rows)
60  * MU: state for visited in refinement pass (1 col x 4 rows)
61  * PI: state for visited in significance pass (1 col * 4 rows)
62  */
63 
64 #define T1_SIGMA_0 (1U << 0)
65 #define T1_SIGMA_1 (1U << 1)
66 #define T1_SIGMA_2 (1U << 2)
67 #define T1_SIGMA_3 (1U << 3)
68 #define T1_SIGMA_4 (1U << 4)
69 #define T1_SIGMA_5 (1U << 5)
70 #define T1_SIGMA_6 (1U << 6)
71 #define T1_SIGMA_7 (1U << 7)
72 #define T1_SIGMA_8 (1U << 8)
73 #define T1_SIGMA_9 (1U << 9)
74 #define T1_SIGMA_10 (1U << 10)
75 #define T1_SIGMA_11 (1U << 11)
76 #define T1_SIGMA_12 (1U << 12)
77 #define T1_SIGMA_13 (1U << 13)
78 #define T1_SIGMA_14 (1U << 14)
79 #define T1_SIGMA_15 (1U << 15)
80 #define T1_SIGMA_16 (1U << 16)
81 #define T1_SIGMA_17 (1U << 17)
82 
83 
104 #define T1_SIGMA_NW T1_SIGMA_0
105 #define T1_SIGMA_N T1_SIGMA_1
106 #define T1_SIGMA_NE T1_SIGMA_2
107 #define T1_SIGMA_W T1_SIGMA_3
108 #define T1_SIGMA_THIS T1_SIGMA_4
109 #define T1_SIGMA_E T1_SIGMA_5
110 #define T1_SIGMA_SW T1_SIGMA_6
111 #define T1_SIGMA_S T1_SIGMA_7
112 #define T1_SIGMA_SE T1_SIGMA_8
113 #define T1_SIGMA_NEIGHBOURS (T1_SIGMA_NW | T1_SIGMA_N | T1_SIGMA_NE | T1_SIGMA_W | T1_SIGMA_E | T1_SIGMA_SW | T1_SIGMA_S | T1_SIGMA_SE)
114 
115 #define T1_CHI_THIS T1_CHI_1
116 #define T1_CHI_THIS_I T1_CHI_1_I
117 #define T1_MU_THIS T1_MU_0
118 #define T1_PI_THIS T1_PI_0
119 #define T1_CHI_S T1_CHI_2
120 
121 #define T1_LUT_SGN_W (1U << 0)
122 #define T1_LUT_SIG_N (1U << 1)
123 #define T1_LUT_SGN_E (1U << 2)
124 #define T1_LUT_SIG_W (1U << 3)
125 #define T1_LUT_SGN_N (1U << 4)
126 #define T1_LUT_SIG_E (1U << 5)
127 #define T1_LUT_SGN_S (1U << 6)
128 #define T1_LUT_SIG_S (1U << 7)
129 
130 
131 /* ----------------------------------------------------------------------- */
132 
133 struct t1_info {
134 
137 
138  int32_t *data;
145 
146  uint32_t w;
147  uint32_t h;
148  uint32_t datasize;
149  uint32_t flagssize;
150  uint32_t data_stride;
151  bool encoder;
152 
153  /* Temporary buffer to concatenate all chunks of a codebock */
154  uint8_t *cblkdatabuffer;
155  /* Maximum size available in cblkdatabuffer */
157 };
158 
160  uint32_t orient, uint32_t roishift, uint32_t cblksty);
161 
163  p_code_block);
164 
165 bool t1_allocate_buffers(t1_info *t1, uint32_t w,
166  uint32_t h);
167 
168 double t1_encode_cblk(t1_info *t1, cblk_enc *cblk,
169  uint32_t max,
170  uint8_t orient, uint32_t compno, uint32_t level,
171  uint32_t qmfbid, double stepsize, uint32_t cblksty,
172  const double *mct_norms,
173  uint32_t mct_numcomps, bool doRateControl);
174 
175 t1_info* t1_create(bool isEncoder);
176 void t1_destroy(t1_info *p_t1);
177 
178 }
grk::t1_info::data
int32_t * data
Definition: t1.h:138
grk::cblk_enc
Definition: t1_common.h:67
grk::t1_info
Definition: t1.h:133
grk::t1_encode_cblk
double t1_encode_cblk(t1_info *t1, cblk_enc *cblk, uint32_t max, uint8_t orient, uint32_t compno, uint32_t level, uint32_t qmfbid, double stepsize, uint32_t cblksty, const double *mct_norms, uint32_t mct_numcomps, bool doRateControl)
grk::t1_info::encoder
bool encoder
Definition: t1.h:151
grk::t1_decode_cblk
bool t1_decode_cblk(t1_info *t1, cblk_dec *cblk, uint32_t orient, uint32_t roishift, uint32_t cblksty)
grk::t1_info::mqc
mqcoder mqc
MQC component.
Definition: t1.h:136
t1_flags.h
grk::t1_info::h
uint32_t h
Definition: t1.h:147
grk::t1_info::flagssize
uint32_t flagssize
Definition: t1.h:149
grk::t1_allocate_buffers
bool t1_allocate_buffers(t1_info *t1, uint32_t w, uint32_t h)
grk::grk_flag
uint32_t grk_flag
Flags for 4 consecutive rows of a column.
Definition: t1.h:43
grk::t1_info::w
uint32_t w
Definition: t1.h:146
grk::t1_info::flags
grk_flag * flags
Flags used by decoder and encoder.
Definition: t1.h:144
grk
Copyright (C) 2016-2020 Grok Image Compression Inc.
Definition: BitIO.h:27
grk::cblk_dec
Definition: t1_common.h:86
grk::t1_info::cblkdatabuffer
uint8_t * cblkdatabuffer
Definition: t1.h:154
grk::t1_info::datasize
uint32_t datasize
Definition: t1.h:148
grk::t1_create
t1_info * t1_create(bool isEncoder)
grk::t1_destroy
void t1_destroy(t1_info *p_t1)
grk::t1_info::data_stride
uint32_t data_stride
Definition: t1.h:150
grk::mqcoder
Definition: mqc.h:42
grk::t1_info::cblkdatabuffersize
uint32_t cblkdatabuffersize
Definition: t1.h:156
grk::t1_code_block_enc_deallocate
void t1_code_block_enc_deallocate(cblk_enc *p_code_block)