2
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
4
* Copyright (c) 2001-2004 Michael David Adams.
8
/* __START_OF_JASPER_LICENSE__
10
* JasPer License Version 2.0
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
16
* All rights reserved.
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:
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.
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
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.
61
* __END_OF_JASPER_LICENSE__
65
* Tree-Structured Filter Bank (TSFB) Library
67
* $Id: jpc_tsfb.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
70
/******************************************************************************\
72
\******************************************************************************/
76
#include "jasper/jas_malloc.h"
77
#include "jasper/jas_seq.h"
85
void jpc_tsfb_getbands2(jpc_tsfb_t *tsfb, int locxstart, int locystart,
86
int xstart, int ystart, int xend, int yend, jpc_tsfb_band_t **bands,
89
/******************************************************************************\
91
\******************************************************************************/
93
jpc_tsfb_t *jpc_cod_gettsfb(int qmfbid, int numlvls)
97
if (!(tsfb = malloc(sizeof(jpc_tsfb_t))))
103
tsfb->qmfb = &jpc_ns_qmfb2d;
107
tsfb->qmfb = &jpc_ft_qmfb2d;
113
tsfb->numlvls = numlvls;
117
void jpc_tsfb_destroy(jpc_tsfb_t *tsfb)
122
int jpc_tsfb_analyze(jpc_tsfb_t *tsfb, jas_seq2d_t *a)
124
return (tsfb->numlvls > 0) ? jpc_tsfb_analyze2(tsfb, jas_seq2d_getref(a,
125
jas_seq2d_xstart(a), jas_seq2d_ystart(a)), jas_seq2d_xstart(a),
126
jas_seq2d_ystart(a), jas_seq2d_width(a),
127
jas_seq2d_height(a), jas_seq2d_rowstep(a), tsfb->numlvls - 1) : 0;
130
int jpc_tsfb_analyze2(jpc_tsfb_t *tsfb, int *a, int xstart, int ystart,
131
int width, int height, int stride, int numlvls)
133
if (width > 0 && height > 0) {
134
if ((*tsfb->qmfb->analyze)(a, xstart, ystart, width, height, stride))
137
if (jpc_tsfb_analyze2(tsfb, a, JPC_CEILDIVPOW2(xstart,
138
1), JPC_CEILDIVPOW2(ystart, 1), JPC_CEILDIVPOW2(
139
xstart + width, 1) - JPC_CEILDIVPOW2(xstart, 1),
140
JPC_CEILDIVPOW2(ystart + height, 1) -
141
JPC_CEILDIVPOW2(ystart, 1), stride, numlvls - 1)) {
149
int jpc_tsfb_synthesize(jpc_tsfb_t *tsfb, jas_seq2d_t *a)
151
return (tsfb->numlvls > 0) ? jpc_tsfb_synthesize2(tsfb,
152
jas_seq2d_getref(a, jas_seq2d_xstart(a), jas_seq2d_ystart(a)),
153
jas_seq2d_xstart(a), jas_seq2d_ystart(a), jas_seq2d_width(a),
154
jas_seq2d_height(a), jas_seq2d_rowstep(a), tsfb->numlvls - 1) : 0;
157
int jpc_tsfb_synthesize2(jpc_tsfb_t *tsfb, int *a, int xstart, int ystart,
158
int width, int height, int stride, int numlvls)
161
if (jpc_tsfb_synthesize2(tsfb, a, JPC_CEILDIVPOW2(xstart, 1),
162
JPC_CEILDIVPOW2(ystart, 1), JPC_CEILDIVPOW2(xstart + width,
163
1) - JPC_CEILDIVPOW2(xstart, 1), JPC_CEILDIVPOW2(ystart +
164
height, 1) - JPC_CEILDIVPOW2(ystart, 1), stride, numlvls -
169
if (width > 0 && height > 0) {
170
if ((*tsfb->qmfb->synthesize)(a, xstart, ystart, width, height, stride)) {
177
int jpc_tsfb_getbands(jpc_tsfb_t *tsfb, uint_fast32_t xstart,
178
uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend,
179
jpc_tsfb_band_t *bands)
181
jpc_tsfb_band_t *band;
184
if (tsfb->numlvls > 0) {
185
jpc_tsfb_getbands2(tsfb, xstart, ystart, xstart, ystart, xend, yend,
186
&band, tsfb->numlvls);
189
band->xstart = xstart;
190
band->ystart = ystart;
193
band->locxstart = xstart;
194
band->locystart = ystart;
195
band->locxend = band->locxstart + band->xend - band->xstart;
196
band->locyend = band->locystart + band->yend - band->ystart;
197
band->orient = JPC_TSFB_LL;
198
band->synenergywt = JPC_FIX_ONE;
204
void jpc_tsfb_getbands2(jpc_tsfb_t *tsfb, int locxstart, int locystart,
205
int xstart, int ystart, int xend, int yend, jpc_tsfb_band_t **bands,
212
jpc_tsfb_band_t *band;
214
newxstart = JPC_CEILDIVPOW2(xstart, 1);
215
newystart = JPC_CEILDIVPOW2(ystart, 1);
216
newxend = JPC_CEILDIVPOW2(xend, 1);
217
newyend = JPC_CEILDIVPOW2(yend, 1);
221
jpc_tsfb_getbands2(tsfb, locxstart, locystart, newxstart, newystart,
222
newxend, newyend, bands, numlvls - 1);
225
band->xstart = JPC_FLOORDIVPOW2(xstart, 1);
226
band->ystart = newystart;
227
band->xend = JPC_FLOORDIVPOW2(xend, 1);
228
band->yend = newyend;
229
band->locxstart = locxstart + newxend - newxstart;
230
band->locystart = locystart;
231
band->locxend = band->locxstart + band->xend - band->xstart;
232
band->locyend = band->locystart + band->yend - band->ystart;
233
band->orient = JPC_TSFB_HL;
234
band->synenergywt = jpc_dbltofix(tsfb->qmfb->hpenergywts[
235
tsfb->numlvls - numlvls] * tsfb->qmfb->lpenergywts[
236
tsfb->numlvls - numlvls]);
240
band->xstart = newxstart;
241
band->ystart = JPC_FLOORDIVPOW2(ystart, 1);
242
band->xend = newxend;
243
band->yend = JPC_FLOORDIVPOW2(yend, 1);
244
band->locxstart = locxstart;
245
band->locystart = locystart + newyend - newystart;
246
band->locxend = band->locxstart + band->xend - band->xstart;
247
band->locyend = band->locystart + band->yend - band->ystart;
248
band->orient = JPC_TSFB_LH;
249
band->synenergywt = jpc_dbltofix(tsfb->qmfb->lpenergywts[
250
tsfb->numlvls - numlvls] * tsfb->qmfb->hpenergywts[
251
tsfb->numlvls - numlvls]);
255
band->xstart = JPC_FLOORDIVPOW2(xstart, 1);
256
band->ystart = JPC_FLOORDIVPOW2(ystart, 1);
257
band->xend = JPC_FLOORDIVPOW2(xend, 1);
258
band->yend = JPC_FLOORDIVPOW2(yend, 1);
259
band->locxstart = locxstart + newxend - newxstart;
260
band->locystart = locystart + newyend - newystart;
261
band->locxend = band->locxstart + band->xend - band->xstart;
262
band->locyend = band->locystart + band->yend - band->ystart;
263
band->orient = JPC_TSFB_HH;
264
band->synenergywt = jpc_dbltofix(tsfb->qmfb->hpenergywts[
265
tsfb->numlvls - numlvls] * tsfb->qmfb->hpenergywts[
266
tsfb->numlvls - numlvls]);
272
band->xstart = xstart;
273
band->ystart = ystart;
276
band->locxstart = locxstart;
277
band->locystart = locystart;
278
band->locxend = band->locxstart + band->xend - band->xstart;
279
band->locyend = band->locystart + band->yend - band->ystart;
280
band->orient = JPC_TSFB_LL;
281
band->synenergywt = jpc_dbltofix(tsfb->qmfb->lpenergywts[
282
tsfb->numlvls - numlvls - 1] * tsfb->qmfb->lpenergywts[
283
tsfb->numlvls - numlvls - 1]);