2 * Copyrigth (c) 2006, M�nica D�ez, LPI-UVA, Spain
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
30 @brief Implementation of the tier-1 coding (coding of code-block coefficients) (T1)
32 The functions in T1_3D.C have for goal to realize the tier-1 coding operation of 3D-EBCOT.
33 The functions in T1_3D.C are used by some function in TCD.C.
36 /** @defgroup T1_3D T1_3D - Implementation of the tier-1 coding */
39 /* ----------------------------------------------------------------------- */
41 /* Neighbourhood of 3D EBCOT (Significance context)*/
42 #define T1_3D_SIG_NE 0x00000001 /*< Context orientation : North-East direction */
43 #define T1_3D_SIG_SE 0x00000002 /*< Context orientation : South-East direction */
44 #define T1_3D_SIG_SW 0x00000004 /*< Context orientation : South-West direction */
45 #define T1_3D_SIG_NW 0x00000008 /* Context orientation : North-West direction */
46 #define T1_3D_SIG_N 0x00000010 /*< Context orientation : North direction */
47 #define T1_3D_SIG_E 0x00000020 /*< Context orientation : East direction */
48 #define T1_3D_SIG_S 0x00000040 /*< Context orientation : South direction */
49 #define T1_3D_SIG_W 0x00000080 /*< Context orientation : West direction */
50 #define T1_3D_SIG_FC 0x00000100 /*< Context orientation : Forward Central direction */
51 #define T1_3D_SIG_BC 0x00000200 /*< Context orientation : Backward Central direction */
52 #define T1_3D_SIG_FNE 0x00000400 /*< Context orientation : Forward North-East direction */
53 #define T1_3D_SIG_FSE 0x00000800 /*< Context orientation : Forward South-East direction */
54 #define T1_3D_SIG_FSW 0x00001000 /*< Context orientation : Forward South-West direction */
55 #define T1_3D_SIG_FNW 0x00002000 /*< Context orientation : Forward North-West direction */
56 #define T1_3D_SIG_FN 0x00004000 /*< Context orientation : Forward North direction */
57 #define T1_3D_SIG_FE 0x00008000 /*< Context orientation : Forward East direction */
58 #define T1_3D_SIG_FS 0x00010000 /*< Context orientation : Forward South direction */
59 #define T1_3D_SIG_FW 0x00020000 /*< Context orientation : Forward West direction */
60 #define T1_3D_SIG_BNE 0x00040000 /*< Context orientation : Backward North-East direction */
61 #define T1_3D_SIG_BSE 0x00080000 /*< Context orientation : Backward South-East direction */
62 #define T1_3D_SIG_BSW 0x00100000 /*< Context orientation : Backward South-West direction */
63 #define T1_3D_SIG_BNW 0x00200000 /*< Context orientation : Backward North-West direction */
64 #define T1_3D_SIG_BN 0x00400000 /*< Context orientation : Backward North direction */
65 #define T1_3D_SIG_BE 0x00800000 /*< Context orientation : Backward East direction */
66 #define T1_3D_SIG_BS 0x01000000 /*< Context orientation : Backward South direction */
67 #define T1_3D_SIG_BW 0x02000000 /*< Context orientation : Backward West direction */
68 #define T1_3D_SIG_COTH (T1_3D_SIG_N|T1_3D_SIG_NE|T1_3D_SIG_E|T1_3D_SIG_SE|T1_3D_SIG_S|T1_3D_SIG_SW|T1_3D_SIG_W|T1_3D_SIG_NW)
69 #define T1_3D_SIG_BOTH (T1_3D_SIG_BN|T1_3D_SIG_BNE|T1_3D_SIG_BE|T1_3D_SIG_BSE|T1_3D_SIG_BS|T1_3D_SIG_BSW|T1_3D_SIG_BW|T1_3D_SIG_BNW|T1_3D_SIG_BC)
70 #define T1_3D_SIG_FOTH (T1_3D_SIG_FN|T1_3D_SIG_FNE|T1_3D_SIG_FE|T1_3D_SIG_FSE|T1_3D_SIG_FS|T1_3D_SIG_FSW|T1_3D_SIG_FW|T1_3D_SIG_FNW|T1_3D_SIG_FC)
71 #define T1_3D_SIG_OTH (T1_3D_SIG_FOTH|T1_3D_SIG_BOTH|T1_3D_SIG_COTH)
72 #define T1_3D_SIG_PRIM (T1_3D_SIG_N|T1_3D_SIG_E|T1_3D_SIG_S|T1_3D_SIG_W|T1_3D_SIG_FC|T1_3D_SIG_BC)
74 #define T1_3D_SGN_N 0x0400
75 #define T1_3D_SGN_E 0x0800
76 #define T1_3D_SGN_S 0x1000
77 #define T1_3D_SGN_W 0x2000
78 #define T1_3D_SGN_F 0x4000
79 #define T1_3D_SGN_B 0x8000
80 #define T1_3D_SGN (T1_3D_SGN_N|T1_3D_SGN_E|T1_3D_SGN_S|T1_3D_SGN_W|T1_3D_SGN_F|T1_3D_SGN_B)
82 #define T1_3D_SIG 0x0001 /*Significance state*/
83 #define T1_3D_REFINE 0x0002 /*Delayed significance*/
84 #define T1_3D_VISIT 0x0004 /*First-pass membership*/
86 #define T1_3D_NUMCTXS_AGG 1
87 #define T1_3D_NUMCTXS_ZC 16
88 #define T1_3D_NUMCTXS_MAG 3
89 #define T1_3D_NUMCTXS_SC 6
90 #define T1_3D_NUMCTXS_UNI 1
92 #define T1_3D_CTXNO_AGG 0
93 #define T1_3D_CTXNO_ZC (T1_3D_CTXNO_AGG+T1_3D_NUMCTXS_AGG) /*1*/
94 #define T1_3D_CTXNO_MAG (T1_3D_CTXNO_ZC+T1_3D_NUMCTXS_ZC) /*17*/
95 #define T1_3D_CTXNO_SC (T1_3D_CTXNO_MAG+T1_3D_NUMCTXS_MAG) /*20*/
96 #define T1_3D_CTXNO_UNI (T1_3D_CTXNO_SC+T1_3D_NUMCTXS_SC) /*26*/
97 #define T1_3D_NUMCTXS (T1_3D_CTXNO_UNI+T1_3D_NUMCTXS_UNI) /*27*/
100 /* ----------------------------------------------------------------------- */
103 Tier-1 coding (coding of code-block coefficients)
105 typedef struct opj_t1_3d {
107 opj_common_ptr cinfo;
112 /** LUTs for decoding normalised MSE */
113 int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
114 int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
115 int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
116 int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
117 /** Codeblock data */
118 int data[T1_CBLKD][T1_CBLKH][T1_CBLKW];
119 /** Context information for each voxel in codeblock */
120 unsigned int flags[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2];
121 /** Voxel information (significance/visited/refined) */
122 int flagSVR[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2];
125 /** @name Exported functions */
127 /* ----------------------------------------------------------------------- */
129 Create a new T1_3D handle
130 and initialize the look-up tables of the Tier-1 coder/decoder
131 @return Returns a new T1 handle if successful, returns NULL otherwise
134 opj_t1_3d_t* t1_3d_create(opj_common_ptr cinfo);
136 Destroy a previously created T1_3D handle
137 @param t1 T1_3D handle to destroy
139 void t1_3d_destroy(opj_t1_3d_t *t1);
141 Encode the code-blocks of a tile
142 @param t1 T1_3D handle
143 @param tile The tile to encode
144 @param tcp Tile coding parameters
146 void t1_3d_encode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
148 Decode the code-blocks of a tile
149 @param t1 T1_3D handle
150 @param tile The tile to decode
151 @param tcp Tile coding parameters
153 void t1_3d_decode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
155 Get weigths of MSE decoding
156 @param nmsedec The normalized MSE reduction
165 returns MSE associated to decoding pass
166 double t1_3d_getwmsedec(int nmsedec, int compno, int levelxy, int levelz, int orient, int bpno, int reversible, double stepsize, int numcomps, int dwtid);
168 /* ----------------------------------------------------------------------- */