Debian Codegraph @

converter/other/jpeg2000/libjasper/jpc/jpc_t1cod.h

raw
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 Software License
11 *
12 * IMAGE POWER JPEG-2000 PUBLIC LICENSE
13 * ************************************
14 *
15 * GRANT:
16 *
17 * Permission is hereby granted, free of charge, to any person (the "User")
18 * obtaining a copy of this software and associated documentation, to deal
19 * in the JasPer Software without restriction, including without limitation
20 * the right to use, copy, modify, merge, publish, distribute, sublicense,
21 * and/or sell copies of the JasPer Software (in source and binary forms),
22 * and to permit persons to whom the JasPer Software is furnished to do so,
23 * provided further that the License Conditions below are met.
24 *
25 * License Conditions
26 * ******************
27 *
28 * A. Redistributions of source code must retain the above copyright notice,
29 * and this list of conditions, and the following disclaimer.
30 *
31 * B. Redistributions in binary form must reproduce the above copyright
32 * notice, and this list of conditions, and the following disclaimer in
33 * the documentation and/or other materials provided with the distribution.
34 *
35 * C. Neither the name of Image Power, Inc. nor any other contributor
36 * (including, but not limited to, the University of British Columbia and
37 * Michael David Adams) may be used to endorse or promote products derived
38 * from this software without specific prior written permission.
39 *
40 * D. User agrees that it shall not commence any action against Image Power,
41 * Inc., the University of British Columbia, Michael David Adams, or any
42 * other contributors (collectively "Licensors") for infringement of any
43 * intellectual property rights ("IPR") held by the User in respect of any
44 * technology that User owns or has a right to license or sublicense and
45 * which is an element required in order to claim compliance with ISO/IEC
46 * 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property
47 * rights worldwide arising under statutory or common law, and whether
48 * or not perfected, including, without limitation, all (i) patents and
49 * patent applications owned or licensable by User; (ii) rights associated
50 * with works of authorship including copyrights, copyright applications,
51 * copyright registrations, mask work rights, mask work applications,
52 * mask work registrations; (iii) rights relating to the protection of
53 * trade secrets and confidential information; (iv) any right analogous
54 * to those set forth in subsections (i), (ii), or (iii) and any other
55 * proprietary rights relating to intangible property (other than trademark,
56 * trade dress, or service mark rights); and (v) divisions, continuations,
57 * renewals, reissues and extensions of the foregoing (as and to the extent
58 * applicable) now existing, hereafter filed, issued or acquired.
59 *
60 * E. If User commences an infringement action against any Licensor(s) then
61 * such Licensor(s) shall have the right to terminate User's license and
62 * all sublicenses that have been granted hereunder by User to other parties.
63 *
64 * F. This software is for use only in hardware or software products that
65 * are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license
66 * or right to this Software is granted for products that do not comply
67 * with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased
68 * from the ISO.
69 *
70 * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
71 * NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
72 * THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND
73 * CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY
74 * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
75 * WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE,
76 * IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING
77 * TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE
78 * OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING
79 * PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS.
80 * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE
81 * IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE
82 * IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY
83 * OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY
84 * OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING,
85 * REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY,
86 * WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE
87 * INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC.,
88 * MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE
89 * JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO
90 * THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
91 * CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION,
92 * DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR
93 * MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF
94 * SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY
95 * OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT
96 * FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR
97 * RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING
98 * FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES,
99 * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT
100 * LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
101 * JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY
102 * TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE
103 * ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS
104 * OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT
105 * KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING
106 * TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS
107 * CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE
108 * NOTICE SPECIFIED IN THIS SECTION.
109 *
110 * __END_OF_JASPER_LICENSE__
111 */
112
113 /*
114 * $Id$
115 */
116
117 #ifndef JPC_T1COD_H
118 #define JPC_T1COD_H
119
120 /******************************************************************************\
121 * Includes.
122 \******************************************************************************/
123
124 #include "jasper/jas_fix.h"
125 #include "jasper/jas_math.h"
126
127 #include "jpc_mqcod.h"
128 #include "jpc_tsfb.h"
129
130 /******************************************************************************\
131 * Constants.
132 \******************************************************************************/
133
134 /* The number of bits used to index into various lookup tables. */
135 #define JPC_NMSEDEC_BITS 7
136 #define JPC_NMSEDEC_FRACBITS (JPC_NMSEDEC_BITS - 1)
137
138 /*
139 * Segment types.
140 */
141
142 /* Invalid. */
143 #define JPC_SEG_INVALID 0
144 /* MQ. */
145 #define JPC_SEG_MQ 1
146 /* Raw. */
147 #define JPC_SEG_RAW 2
148
149 /* The nominal word size. */
150 #define JPC_PREC 32
151
152 /* Tier-1 coding pass types. */
153 #define JPC_SIGPASS 0 /* significance */
154 #define JPC_REFPASS 1 /* refinement */
155 #define JPC_CLNPASS 2 /* cleanup */
156
157 /*
158 * Per-sample state information for tier-1 coding.
159 */
160
161 /* The northeast neighbour has been found to be significant. */
162 #define JPC_NESIG 0x0001
163 /* The southeast neighbour has been found to be significant. */
164 #define JPC_SESIG 0x0002
165 /* The southwest neighbour has been found to be significant. */
166 #define JPC_SWSIG 0x0004
167 /* The northwest neighbour has been found to be significant. */
168 #define JPC_NWSIG 0x0008
169 /* The north neighbour has been found to be significant. */
170 #define JPC_NSIG 0x0010
171 /* The east neighbour has been found to be significant. */
172 #define JPC_ESIG 0x0020
173 /* The south neighbour has been found to be significant. */
174 #define JPC_SSIG 0x0040
175 /* The west neighbour has been found to be significant. */
176 #define JPC_WSIG 0x0080
177 /* The significance mask for 8-connected neighbours. */
178 #define JPC_OTHSIGMSK \
179 (JPC_NSIG | JPC_NESIG | JPC_ESIG | JPC_SESIG | JPC_SSIG | JPC_SWSIG | JPC_WSIG | JPC_NWSIG)
180 /* The significance mask for 4-connected neighbours. */
181 #define JPC_PRIMSIGMSK (JPC_NSIG | JPC_ESIG | JPC_SSIG | JPC_WSIG)
182
183 /* The north neighbour is negative in value. */
184 #define JPC_NSGN 0x0100
185 /* The east neighbour is negative in value. */
186 #define JPC_ESGN 0x0200
187 /* The south neighbour is negative in value. */
188 #define JPC_SSGN 0x0400
189 /* The west neighbour is negative in value. */
190 #define JPC_WSGN 0x0800
191 /* The sign mask for 4-connected neighbours. */
192 #define JPC_SGNMSK (JPC_NSGN | JPC_ESGN | JPC_SSGN | JPC_WSGN)
193
194 /* This sample has been found to be significant. */
195 #define JPC_SIG 0x1000
196 /* The sample has been refined. */
197 #define JPC_REFINE 0x2000
198 /* This sample has been processed during the significance pass. */
199 #define JPC_VISIT 0x4000
200
201 /* The number of aggregation contexts. */
202 #define JPC_NUMAGGCTXS 1
203 /* The number of zero coding contexts. */
204 #define JPC_NUMZCCTXS 9
205 /* The number of magnitude contexts. */
206 #define JPC_NUMMAGCTXS 3
207 /* The number of sign coding contexts. */
208 #define JPC_NUMSCCTXS 5
209 /* The number of uniform contexts. */
210 #define JPC_NUMUCTXS 1
211
212 /* The context ID for the first aggregation context. */
213 #define JPC_AGGCTXNO 0
214 /* The context ID for the first zero coding context. */
215 #define JPC_ZCCTXNO (JPC_AGGCTXNO + JPC_NUMAGGCTXS)
216 /* The context ID for the first magnitude context. */
217 #define JPC_MAGCTXNO (JPC_ZCCTXNO + JPC_NUMZCCTXS)
218 /* The context ID for the first sign coding context. */
219 #define JPC_SCCTXNO (JPC_MAGCTXNO + JPC_NUMMAGCTXS)
220 /* The context ID for the first uniform context. */
221 #define JPC_UCTXNO (JPC_SCCTXNO + JPC_NUMSCCTXS)
222 /* The total number of contexts. */
223 #define JPC_NUMCTXS (JPC_UCTXNO + JPC_NUMUCTXS)
224
225 /******************************************************************************\
226 * External data.
227 \******************************************************************************/
228
229 /* These lookup tables are used by various macros/functions. */
230 /* Do not access these lookup tables directly. */
231 extern int jpc_zcctxnolut[];
232 extern int jpc_spblut[];
233 extern int jpc_scctxnolut[];
234 extern int jpc_magctxnolut[];
235 extern jpc_fix_t jpc_refnmsedec[];
236 extern jpc_fix_t jpc_signmsedec[];
237 extern jpc_fix_t jpc_refnmsedec0[];
238 extern jpc_fix_t jpc_signmsedec0[];
239
240 /* The initial settings for the MQ contexts. */
241 extern jpc_mqctx_t jpc_mqctxs[];
242
243 /******************************************************************************\
244 * Functions and macros.
245 \******************************************************************************/
246
247 /* Initialize the MQ contexts. */
248 void jpc_initctxs(jpc_mqctx_t *ctxs);
249
250 /* Get the zero coding context. */
251 int jpc_getzcctxno(int f, int orient);
252 #define JPC_GETZCCTXNO(f, orient) \
253 (jpc_zcctxnolut[((orient) << 8) | ((f) & JPC_OTHSIGMSK)])
254
255 /* Get the sign prediction bit. */
256 int jpc_getspb(int f);
257 #define JPC_GETSPB(f) \
258 (jpc_spblut[((f) & (JPC_PRIMSIGMSK | JPC_SGNMSK)) >> 4])
259
260 /* Get the sign coding context. */
261 int jpc_getscctxno(int f);
262 #define JPC_GETSCCTXNO(f) \
263 (jpc_scctxnolut[((f) & (JPC_PRIMSIGMSK | JPC_SGNMSK)) >> 4])
264
265 /* Get the magnitude context. */
266 int jpc_getmagctxno(int f);
267 #define JPC_GETMAGCTXNO(f) \
268 (jpc_magctxnolut[((f) & JPC_OTHSIGMSK) | ((((f) & JPC_REFINE) != 0) << 11)])
269
270 /* Get the normalized MSE reduction for significance passes. */
271 #define JPC_GETSIGNMSEDEC(x, bitpos) jpc_getsignmsedec_macro(x, bitpos)
272 jpc_fix_t jpc_getsignmsedec_func(jpc_fix_t x, int bitpos);
273 #define jpc_getsignmsedec_macro(x, bitpos) \
274 ((bitpos > JPC_NMSEDEC_FRACBITS) ? jpc_signmsedec[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)] : \
275 (jpc_signmsedec0[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)]))
276
277 /* Get the normalized MSE reduction for refinement passes. */
278 #define JPC_GETREFNMSEDEC(x, bitpos) jpc_getrefnmsedec_macro(x, bitpos)
279 jpc_fix_t jpc_refsignmsedec_func(jpc_fix_t x, int bitpos);
280 #define jpc_getrefnmsedec_macro(x, bitpos) \
281 ((bitpos > JPC_NMSEDEC_FRACBITS) ? jpc_refnmsedec[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)] : \
282 (jpc_refnmsedec0[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)]))
283
284 /* Arithmetic shift right (with ability to shift left also). */
285 #define JPC_ASR(x, n) \
286 (((n) >= 0) ? ((x) >> (n)) : ((x) << (-(n))))
287
288 /* Update the per-sample state information. */
289 #define JPC_UPDATEFLAGS4(fp, rowstep, s, vcausalflag) \
290 { \
291 register jpc_fix_t *np = (fp) - (rowstep); \
292 register jpc_fix_t *sp = (fp) + (rowstep); \
293 if ((vcausalflag)) { \
294 sp[-1] |= JPC_NESIG; \
295 sp[1] |= JPC_NWSIG; \
296 if (s) { \
297 *sp |= JPC_NSIG | JPC_NSGN; \
298 (fp)[-1] |= JPC_ESIG | JPC_ESGN; \
299 (fp)[1] |= JPC_WSIG | JPC_WSGN; \
300 } else { \
301 *sp |= JPC_NSIG; \
302 (fp)[-1] |= JPC_ESIG; \
303 (fp)[1] |= JPC_WSIG; \
304 } \
305 } else { \
306 np[-1] |= JPC_SESIG; \
307 np[1] |= JPC_SWSIG; \
308 sp[-1] |= JPC_NESIG; \
309 sp[1] |= JPC_NWSIG; \
310 if (s) { \
311 *np |= JPC_SSIG | JPC_SSGN; \
312 *sp |= JPC_NSIG | JPC_NSGN; \
313 (fp)[-1] |= JPC_ESIG | JPC_ESGN; \
314 (fp)[1] |= JPC_WSIG | JPC_WSGN; \
315 } else { \
316 *np |= JPC_SSIG; \
317 *sp |= JPC_NSIG; \
318 (fp)[-1] |= JPC_ESIG; \
319 (fp)[1] |= JPC_WSIG; \
320 } \
321 } \
322 }
323
324 /* Initialize the lookup tables used by the codec. */
325 void jpc_initluts(void);
326
327 /* Get the nominal gain associated with a particular band. */
328 int JPC_NOMINALGAIN(int qmfbid, int numlvls, int lvlno, int orient);
329
330 /* Get the coding pass type. */
331 int JPC_PASSTYPE(int passno);
332
333 /* Get the segment type. */
334 int JPC_SEGTYPE(int passno, int firstpassno, int bypass);
335
336 /* Get the number of coding passess in the segment. */
337 int JPC_SEGPASSCNT(int passno, int firstpassno, int numpasses, int bypass,
338 int termall);
339
340 /* Is the coding pass terminated? */
341 int JPC_ISTERMINATED(int passno, int firstpassno, int numpasses, int termall,
342 int lazy);
343
344 #endif