jpc_t2cod.h Source File

jpc_t2cod.h
1 /*
2 * Copyright (c) 1999-2000 Image Power, Inc. and the University of
3 * British Columbia.
4 * Copyright (c) 2001-2002 Michael David Adams.
5 * All rights reserved.
6 */
7
8 /* __START_OF_JASPER_LICENSE__
9 *
10 * JasPer License Version 2.0
11 *
12 * Copyright (c) 2001-2006 Michael David Adams
13 * Copyright (c) 1999-2000 Image Power, Inc.
14 * Copyright (c) 1999-2000 The University of British Columbia
15 *
16 * All rights reserved.
17 *
18 * Permission is hereby granted, free of charge, to any person (the
19 * "User") obtaining a copy of this software and associated documentation
20 * files (the "Software"), to deal in the Software without restriction,
21 * including without limitation the rights to use, copy, modify, merge,
22 * publish, distribute, and/or sell copies of the Software, and to permit
23 * persons to whom the Software is furnished to do so, subject to the
24 * following conditions:
25 *
26 * 1. The above copyright notices and this permission notice (which
27 * includes the disclaimer below) shall be included in all copies or
28 * substantial portions of the Software.
29 *
30 * 2. The name of a copyright holder shall not be used to endorse or
31 * promote products derived from the Software without specific prior
32 * written permission.
33 *
34 * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
35 * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
36 * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
37 * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
38 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
39 * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
40 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
41 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
42 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
43 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
44 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
45 * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
46 * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
47 * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
48 * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
49 * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
50 * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
51 * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
52 * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
53 * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
54 * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
55 * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
56 * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
57 * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
58 * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
59 * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
60 *
61 * __END_OF_JASPER_LICENSE__
62 */
63
64 /*
65 * Tier-2 Coding Library
66 *
67 * $Id$
68 */
69
70 #ifndef JPC_T2COD_H
71 #define JPC_T2COD_H
72
73 /******************************************************************************\
74 * Includes.
75 \******************************************************************************/
76
77 #include "jpc_cs.h"
78
79 /******************************************************************************\
80 * Types.
81 \******************************************************************************/
82
83 /* Progression change list. */
84
85 typedef struct {
86
87 /* The number of progression changes. */
88 int numpchgs;
89
90 /* The maximum number of progression changes that can be accomodated
91 without growing the progression change array. */
92 int maxpchgs;
93
94 /* The progression changes. */
95 jpc_pchg_t **pchgs;
96
97 } jpc_pchglist_t;
98
99 /* Packet iterator per-resolution-level information. */
100
101 typedef struct {
102
103 /* The number of precincts. */
104 int numprcs;
105
106 /* The last layer processed for each precinct. */
107 int *prclyrnos;
108
109 /* The precinct width exponent. */
110 int prcwidthexpn;
111
112 /* The precinct height exponent. */
113 int prcheightexpn;
114
115 /* The number of precincts spanning the resolution level in the horizontal
116 direction. */
117 int numhprcs;
118
119 } jpc_pirlvl_t;
120
121 /* Packet iterator per-component information. */
122
123 typedef struct {
124
125 /* The number of resolution levels. */
126 int numrlvls;
127
128 /* The per-resolution-level information. */
129 jpc_pirlvl_t *pirlvls;
130
131 /* The horizontal sampling period. */
132 uint_fast32_t hsamp;
133
134 /* The vertical sampling period. */
135 uint_fast32_t vsamp;
136
137 } jpc_picomp_t;
138
139 /* Packet iterator class. */
140
141 typedef struct {
142
143 /* The number of layers. */
144 int numlyrs;
145
146 /* The number of resolution levels. */
147 int maxrlvls;
148
149 /* The number of components. */
150 int numcomps;
151
152 /* The per-component information. */
153 jpc_picomp_t *picomps;
154
155 /* The current component. */
156 jpc_picomp_t *picomp;
157
158 /* The current resolution level. */
159 jpc_pirlvl_t *pirlvl;
160
161 /* The number of the current component. */
162 int compno;
163
164 /* The number of the current resolution level. */
165 int rlvlno;
166
167 /* The number of the current precinct. */
168 int prcno;
169
170 /* The number of the current layer. */
171 int lyrno;
172
173 /* The x-coordinate of the current position. */
174 uint_fast32_t x;
175
176 /* The y-coordinate of the current position. */
177 uint_fast32_t y;
178
179 /* The horizontal step size. */
180 uint_fast32_t xstep;
181
182 /* The vertical step size. */
183 uint_fast32_t ystep;
184
185 /* The x-coordinate of the top-left corner of the tile on the reference
186 grid. */
187 uint_fast32_t xstart;
188
189 /* The y-coordinate of the top-left corner of the tile on the reference
190 grid. */
191 uint_fast32_t ystart;
192
193 /* The x-coordinate of the bottom-right corner of the tile on the
194 reference grid (plus one). */
195 uint_fast32_t xend;
196
197 /* The y-coordinate of the bottom-right corner of the tile on the
198 reference grid (plus one). */
199 uint_fast32_t yend;
200
201 /* The current progression change. */
202 jpc_pchg_t *pchg;
203
204 /* The progression change list. */
205 jpc_pchglist_t *pchglist;
206
207 /* The progression to use in the absense of explicit specification. */
208 jpc_pchg_t defaultpchg;
209
210 /* The current progression change number. */
211 int pchgno;
212
213 /* Is this the first time in the current progression volume? */
214 bool prgvolfirst;
215
216 /* Is the current iterator value valid? */
217 bool valid;
218
219 /* The current packet number. */
220 int pktno;
221
222 } jpc_pi_t;
223
224 /******************************************************************************\
225 * Functions/macros for packet iterators.
226 \******************************************************************************/
227
228 /* Create a packet iterator. */
229 jpc_pi_t *jpc_pi_create0(void);
230
231 /* Destroy a packet iterator. */
232 void jpc_pi_destroy(jpc_pi_t *pi);
233
234 /* Add a progression change to a packet iterator. */
235 int jpc_pi_addpchg(jpc_pi_t *pi, jpc_pocpchg_t *pchg);
236
237 /* Prepare a packet iterator for iteration. */
238 int jpc_pi_init(jpc_pi_t *pi);
239
240 /* Set the iterator to the first packet. */
241 int jpc_pi_begin(jpc_pi_t *pi);
242
243 /* Proceed to the next packet in sequence. */
244 int jpc_pi_next(jpc_pi_t *pi);
245
246 /* Get the index of the current packet. */
247 #define jpc_pi_getind(pi) ((pi)->pktno)
248
249 /* Get the component number of the current packet. */
250 #define jpc_pi_cmptno(pi) (assert(pi->valid), (pi)->compno)
251
252 /* Get the resolution level of the current packet. */
253 #define jpc_pi_rlvlno(pi) (assert(pi->valid), (pi)->rlvlno)
254
255 /* Get the layer number of the current packet. */
256 #define jpc_pi_lyrno(pi) (assert(pi->valid), (pi)->lyrno)
257
258 /* Get the precinct number of the current packet. */
259 #define jpc_pi_prcno(pi) (assert(pi->valid), (pi)->prcno)
260
261 /* Get the progression order for the current packet. */
262 #define jpc_pi_prg(pi) (assert(pi->valid), (pi)->pchg->prgord)
263
264 /******************************************************************************\
265 * Functions/macros for progression change lists.
266 \******************************************************************************/
267
268 /* Create a progression change list. */
269 jpc_pchglist_t *jpc_pchglist_create(void);
270
271 /* Destroy a progression change list. */
272 void jpc_pchglist_destroy(jpc_pchglist_t *pchglist);
273
274 /* Insert a new element into a progression change list. */
275 int jpc_pchglist_insert(jpc_pchglist_t *pchglist, int pchgno, jpc_pchg_t *pchg);
276
277 /* Remove an element from a progression change list. */
278 jpc_pchg_t *jpc_pchglist_remove(jpc_pchglist_t *pchglist, int pchgno);
279
280 /* Get an element from a progression change list. */
281 jpc_pchg_t *jpc_pchglist_get(jpc_pchglist_t *pchglist, int pchgno);
282
283 /* Copy a progression change list. */
284 jpc_pchglist_t *jpc_pchglist_copy(jpc_pchglist_t *pchglist);
285
286 /* Get the number of elements in a progression change list. */
287 int jpc_pchglist_numpchgs(jpc_pchglist_t *pchglist);
288
289 /******************************************************************************\
290 * Functions/macros for progression changes.
291 \******************************************************************************/
292
293 /* Destroy a progression change. */
294 void jpc_pchg_destroy(jpc_pchg_t *pchg);
295
296 /* Copy a progression change. */
297 jpc_pchg_t *jpc_pchg_copy(jpc_pchg_t *pchg);
298
299 #endif