~ubuntu-branches/ubuntu/jaunty/ghostscript/jaunty-updates

« back to all changes in this revision

Viewing changes to jasper/src/libjasper/jpc/jpc_qmfb.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2009-01-20 16:40:45 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120164045-lnfhi0n30o5lwhwa
Tags: 8.64.dfsg.1~svn9377-0ubuntu1
* New upstream release (SVN rev 9377)
   o Fixes many bugs concerning PDF rendering, to make the PDF printing
     workflow correctly working.
   o Fixes long-standing bugs in many drivers, like input paper tray and
     duplex options not working for the built-in PCL 4, 5, 5c, 5e, and
     6/XL drivers, PDF input not working for bjc600, bjc800, and cups
     output devices, several options not working and uninitialized
     memory with cups output device.
   o Merged nearly all patches of the Ubuntu and Debian packages upstream.
   o Fixes LP: #317810, LP: #314439, LP: #314018.
* debian/patches/03_libpaper_support.dpatch,
  debian/patches/11_gs-cjk_font_glyph_handling_fix.dpatch,
  debian/patches/12_gs-cjk_vertical_writing_metrics_fix.dpatch,
  debian/patches/13_gs-cjk_cjkps_examples.dpatch,
  debian/patches/20_bbox_segv_fix.dpatch,
  debian/patches/21_brother_7x0_gdi_fix.dpatch,
  debian/patches/22_epsn_margin_workaround.dpatch,
  debian/patches/24_gs_man_fix.dpatch,
  debian/patches/25_toolbin_insecure_tmp_usage_fix.dpatch,
  debian/patches/26_assorted_script_fixes.dpatch,
  debian/patches/29_gs_css_fix.dpatch,
  debian/patches/30_ps2pdf_man_improvement.dpatch,
  debian/patches/31_fix-gc-sigbus.dpatch,
  debian/patches/34_ftbfs-on-hurd-fix.dpatch,
  debian/patches/35_disable_libcairo.dpatch,
  debian/patches/38_pxl-duplex.dpatch,
  debian/patches/39_pxl-resolution.dpatch,
  debian/patches/42_gs-init-ps-delaybind-fix.dpatch,
  debian/patches/45_bjc600-bjc800-pdf-input.dpatch,
  debian/patches/48_cups-output-device-pdf-duplex-uninitialized-memory-fix.dpatch,
  debian/patches/50_lips4-floating-point-exception.dpatch,
  debian/patches/52_cups-device-logging.dpatch,
  debian/patches/55_pcl-input-slot-fix.dpatch,
  debian/patches/57_pxl-input-slot-fix.dpatch,
  debian/patches/60_pxl-cups-driver-pdf.dpatch,
  debian/patches/62_onebitcmyk-pdf.dpatch,
  debian/patches/65_too-big-temp-files-1.dpatch,
  debian/patches/67_too-big-temp-files-2.dpatch,
  debian/patches/70_take-into-account-data-in-stream-buffer-before-refill.dpatch:
  Removed, applied upstream.
* debian/patches/01_docdir_fix_for_debian.dpatch,
  debian/patches/02_gs_man_fix_debian.dpatch,
  debian/patches/01_docdir-fix-for-debian.dpatch,
  debian/patches/02_docdir-fix-for-debian.dpatch: Renamed patches to
  make merging with Debian easier.
* debian/patches/32_improve-handling-of-media-size-changes-from-gv.dpatch, 
  debian/patches/33_bad-params-to-xinitimage-on-large-bitmaps.dpatch:
  regenerated for new source directory structure.
* debian/rules: Corrected paths to remove cidfmap (it is in Resource/Init/
  in GS 8.64) and to install headers (source paths are psi/ and base/ now).
* debian/rules: Remove all fontmaps, as DeFoMa replaces them.
* debian/local/pdftoraster/pdftoraster.c,
  debian/local/pdftoraster/pdftoraster.convs, debian/rules: Removed
  added pdftoraster filter and use the one which comes with Ghostscript.
* debian/ghostscript.links: s/8.63/8.64/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 1999-2000 Image Power, Inc. and the University of
3
 
 *   British Columbia.
4
 
 * Copyright (c) 2001-2003 Michael David Adams.
5
 
 * Copyright (c) 2005-2006 Artifex Software, Inc.
6
 
 *
7
 
 * All rights reserved.
8
 
 */
9
 
 
10
 
/* __START_OF_JASPER_LICENSE__
11
 
 * 
12
 
 * JasPer License Version 2.0
13
 
 * 
14
 
 * Copyright (c) 1999-2000 Image Power, Inc.
15
 
 * Copyright (c) 1999-2000 The University of British Columbia
16
 
 * Copyright (c) 2001-2003 Michael David Adams
17
 
 * 
18
 
 * All rights reserved.
19
 
 * 
20
 
 * Permission is hereby granted, free of charge, to any person (the
21
 
 * "User") obtaining a copy of this software and associated documentation
22
 
 * files (the "Software"), to deal in the Software without restriction,
23
 
 * including without limitation the rights to use, copy, modify, merge,
24
 
 * publish, distribute, and/or sell copies of the Software, and to permit
25
 
 * persons to whom the Software is furnished to do so, subject to the
26
 
 * following conditions:
27
 
 * 
28
 
 * 1.  The above copyright notices and this permission notice (which
29
 
 * includes the disclaimer below) shall be included in all copies or
30
 
 * substantial portions of the Software.
31
 
 * 
32
 
 * 2.  The name of a copyright holder shall not be used to endorse or
33
 
 * promote products derived from the Software without specific prior
34
 
 * written permission.
35
 
 * 
36
 
 * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
37
 
 * LICENSE.  NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
38
 
 * THIS DISCLAIMER.  THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
39
 
 * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
40
 
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
41
 
 * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO
42
 
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
43
 
 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
44
 
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
45
 
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
46
 
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  NO ASSURANCES ARE
47
 
 * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
48
 
 * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
49
 
 * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
50
 
 * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
51
 
 * PROPERTY RIGHTS OR OTHERWISE.  AS A CONDITION TO EXERCISING THE RIGHTS
52
 
 * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
53
 
 * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY.  THE SOFTWARE
54
 
 * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
55
 
 * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
56
 
 * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
57
 
 * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
58
 
 * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
59
 
 * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
60
 
 * RISK ACTIVITIES").  THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
61
 
 * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
62
 
 * 
63
 
 * __END_OF_JASPER_LICENSE__
64
 
 */
65
 
 
66
 
/*
67
 
 * Quadrature Mirror-Image Filter Bank (QMFB) Library
68
 
 *
69
 
 * $Id$
70
 
 */
71
 
 
72
 
/******************************************************************************\
73
 
* Includes.
74
 
\******************************************************************************/
75
 
 
76
 
#include <assert.h>
77
 
 
78
 
#include "jasper/jas_fix.h"
79
 
#include "jasper/jas_malloc.h"
80
 
#include "jasper/jas_math.h"
81
 
#include "jasper/jas_debug.h"
82
 
 
83
 
#include "jpc_qmfb.h"
84
 
#include "jpc_tsfb.h"
85
 
#include "jpc_math.h"
86
 
 
87
 
#ifndef USE_ASM_WIN32
88
 
# if defined(_WIN32) && !defined(_WIN64) && ! defined(__BORLANDC__)
89
 
#  define USE_ASM_WIN32
90
 
# endif
91
 
#endif
92
 
 
93
 
/******************************************************************************\
94
 
*
95
 
\******************************************************************************/
96
 
 
97
 
static jpc_qmfb1d_t *jpc_qmfb1d_create(void);
98
 
 
99
 
static int jpc_ft_getnumchans(jpc_qmfb1d_t *qmfb);
100
 
static int jpc_ft_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
101
 
static int jpc_ft_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
102
 
static void jpc_ft_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
103
 
static void jpc_ft_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
104
 
 
105
 
static int jpc_ns_getnumchans(jpc_qmfb1d_t *qmfb);
106
 
static int jpc_ns_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
107
 
static int jpc_ns_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
108
 
static void jpc_ns_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
109
 
 
110
 
 
111
 
static void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
112
 
 
113
 
#ifdef USE_ASM_WIN32
114
 
static void jpc_win32_ns_synthesize( jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
115
 
#endif
116
 
 
117
 
/******************************************************************************\
118
 
*
119
 
\******************************************************************************/
120
 
 
121
 
jpc_qmfb1dops_t jpc_ft_ops = {
122
 
        jpc_ft_getnumchans,
123
 
        jpc_ft_getanalfilters,
124
 
        jpc_ft_getsynfilters,
125
 
        jpc_ft_analyze,
126
 
        jpc_ft_synthesize
127
 
};
128
 
 
129
 
jpc_qmfb1dops_t jpc_ns_ops = {
130
 
        jpc_ns_getnumchans,
131
 
        jpc_ns_getanalfilters,
132
 
        jpc_ns_getsynfilters,
133
 
        jpc_ns_analyze,
134
 
#ifdef USE_ASM_WIN32
135
 
        jpc_win32_ns_synthesize
136
 
#else
137
 
        jpc_ns_synthesize
138
 
#endif
139
 
};
140
 
 
141
 
/******************************************************************************\
142
 
*
143
 
\******************************************************************************/
144
 
 
145
 
static void jpc_qmfb1d_setup(jpc_fix_t *startptr, int startind, int endind,
146
 
  int intrastep, jpc_fix_t **lstartptr, int *lstartind, int *lendind,
147
 
  jpc_fix_t **hstartptr, int *hstartind, int *hendind)
148
 
{
149
 
        *lstartind = JPC_CEILDIVPOW2(startind, 1);
150
 
        *lendind = JPC_CEILDIVPOW2(endind, 1);
151
 
        *hstartind = JPC_FLOORDIVPOW2(startind, 1);
152
 
        *hendind = JPC_FLOORDIVPOW2(endind, 1);
153
 
        *lstartptr = startptr;
154
 
        *hstartptr = &startptr[(*lendind - *lstartind) * intrastep];
155
 
}
156
 
 
157
 
static void jpc_qmfb1d_split(jpc_fix_t *startptr, int startind, int endind,
158
 
  register int step, jpc_fix_t *lstartptr, int lstartind, int lendind,
159
 
  jpc_fix_t *hstartptr, int hstartind, int hendind)
160
 
{
161
 
        int bufsize = JPC_CEILDIVPOW2(endind - startind, 2);
162
 
#if !defined(HAVE_VLA)
163
 
#define QMFB_SPLITBUFSIZE 4096
164
 
        jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE];
165
 
#else
166
 
        jpc_fix_t splitbuf[bufsize];
167
 
#endif
168
 
        jpc_fix_t *buf = splitbuf;
169
 
        int llen;
170
 
        int hlen;
171
 
        int twostep;
172
 
        jpc_fix_t *tmpptr;
173
 
        register jpc_fix_t *ptr;
174
 
        register jpc_fix_t *hptr;
175
 
        register jpc_fix_t *lptr;
176
 
        register int n;
177
 
        int state;
178
 
 
179
 
        twostep = step << 1;
180
 
        llen = lendind - lstartind;
181
 
        hlen = hendind - hstartind;
182
 
 
183
 
#if !defined(HAVE_VLA)
184
 
        /* Get a buffer. */
185
 
        if (bufsize > QMFB_SPLITBUFSIZE) {
186
 
                if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
187
 
                        /* We have no choice but to commit suicide in this case. */
188
 
                        jas_error(      JAS_ERR_MALLOC_FAILURE_JPC_QMFB1D_SPLIT,
189
 
                                                "JAS_ERR_MALLOC_FAILURE_JPC_QMFB1D_SPLIT"
190
 
                                        );
191
 
                        return;
192
 
                }
193
 
        }
194
 
#endif
195
 
 
196
 
        if (hstartind < lstartind) {
197
 
                /* The first sample in the input signal is to appear
198
 
                  in the highpass subband signal. */
199
 
                /* Copy the appropriate samples into the lowpass subband
200
 
                  signal, saving any samples destined for the highpass subband
201
 
                  signal as they are overwritten. */
202
 
                tmpptr = buf;
203
 
                ptr = &startptr[step];
204
 
                lptr = lstartptr;
205
 
                n = llen;
206
 
                state = 1;
207
 
                while (n-- > 0) {
208
 
                        if (state) {
209
 
                                *tmpptr = *lptr;
210
 
                                ++tmpptr;
211
 
                        }
212
 
                        *lptr = *ptr;
213
 
                        ptr += twostep;
214
 
                        lptr += step;
215
 
                        state ^= 1;
216
 
                }
217
 
                /* Copy the appropriate samples into the highpass subband
218
 
                  signal. */
219
 
                /* Handle the nonoverwritten samples. */
220
 
                hptr = &hstartptr[(hlen - 1) * step];
221
 
                ptr = &startptr[(((llen + hlen - 1) >> 1) << 1) * step];
222
 
                n = hlen - (tmpptr - buf);
223
 
                while (n-- > 0) {
224
 
                        *hptr = *ptr;
225
 
                        hptr -= step;
226
 
                        ptr -= twostep;
227
 
                }
228
 
                /* Handle the overwritten samples. */
229
 
                n = tmpptr - buf;
230
 
                while (n-- > 0) {
231
 
                        --tmpptr;
232
 
                        *hptr = *tmpptr;
233
 
                        hptr -= step;
234
 
                }
235
 
        } else {
236
 
                /* The first sample in the input signal is to appear
237
 
                  in the lowpass subband signal. */
238
 
                /* Copy the appropriate samples into the lowpass subband
239
 
                  signal, saving any samples for the highpass subband
240
 
                  signal as they are overwritten. */
241
 
                state = 0;
242
 
                ptr = startptr;
243
 
                lptr = lstartptr;
244
 
                tmpptr = buf;
245
 
                n = llen;
246
 
                while (n-- > 0) {
247
 
                        if (state) {
248
 
                                *tmpptr = *lptr;
249
 
                                ++tmpptr;
250
 
                        }
251
 
                        *lptr = *ptr;
252
 
                        ptr += twostep;
253
 
                        lptr += step;
254
 
                        state ^= 1;
255
 
                }
256
 
                /* Copy the appropriate samples into the highpass subband
257
 
                  signal. */
258
 
                /* Handle the nonoverwritten samples. */
259
 
                ptr = &startptr[((((llen + hlen) >> 1) << 1) - 1) * step];
260
 
                hptr = &hstartptr[(hlen - 1) * step];
261
 
                n = hlen - (tmpptr - buf);
262
 
                while (n-- > 0) {
263
 
                        *hptr = *ptr;
264
 
                        ptr -= twostep;
265
 
                        hptr -= step;
266
 
                }
267
 
                /* Handle the overwritten samples. */
268
 
                n = tmpptr - buf;
269
 
                while (n-- > 0) {
270
 
                        --tmpptr;
271
 
                        *hptr = *tmpptr;
272
 
                        hptr -= step;
273
 
                }
274
 
        }
275
 
 
276
 
#if !defined(HAVE_VLA)
277
 
        /* If the split buffer was allocated on the heap, free this memory. */
278
 
        if (buf != splitbuf) {
279
 
                jas_free(buf);
280
 
        }
281
 
#endif
282
 
}
283
 
 
284
 
static void jpc_qmfb1d_join(jpc_fix_t *startptr, int startind, int endind,
285
 
  register int step, jpc_fix_t *lstartptr, int lstartind, int lendind,
286
 
  jpc_fix_t *hstartptr, int hstartind, int hendind)
287
 
{
288
 
        int bufsize = JPC_CEILDIVPOW2(endind - startind, 2);
289
 
#if !defined(HAVE_VLA)
290
 
#define QMFB_JOINBUFSIZE        4096
291
 
        jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
292
 
#else
293
 
        jpc_fix_t joinbuf[bufsize];
294
 
#endif
295
 
        jpc_fix_t *buf = joinbuf;
296
 
        int llen;
297
 
        int hlen;
298
 
        int twostep;
299
 
        jpc_fix_t *tmpptr;
300
 
        register jpc_fix_t *ptr;
301
 
        register jpc_fix_t *hptr;
302
 
        register jpc_fix_t *lptr;
303
 
        register int n;
304
 
        int state;
305
 
 
306
 
#if !defined(HAVE_VLA)
307
 
        /* Allocate memory for the join buffer from the heap. */
308
 
        if (bufsize > QMFB_JOINBUFSIZE) {
309
 
                if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
310
 
                        /* We have no choice but to commit suicide. */
311
 
                        jas_error(      JAS_ERR_MALLOC_FAILURE_JPC_QMFB1D_JOIN,
312
 
                                                "JAS_ERR_MALLOC_FAILURE_JPC_QMFB1D_JOIN"
313
 
                                        );
314
 
                        return;
315
 
                }
316
 
        }
317
 
#endif
318
 
 
319
 
        twostep = step << 1;
320
 
        llen = lendind - lstartind;
321
 
        hlen = hendind - hstartind;
322
 
 
323
 
        if (hstartind < lstartind) {
324
 
                /* The first sample in the highpass subband signal is to
325
 
                  appear first in the output signal. */
326
 
                /* Copy the appropriate samples into the first phase of the
327
 
                  output signal. */
328
 
                tmpptr = buf;
329
 
                hptr = hstartptr;
330
 
                ptr = startptr;
331
 
                n = (llen + 1) >> 1;
332
 
                while (n-- > 0) {
333
 
                        *tmpptr = *ptr;
334
 
                        *ptr = *hptr;
335
 
                        ++tmpptr;
336
 
                        ptr += twostep;
337
 
                        hptr += step;
338
 
                }
339
 
                n = hlen - ((llen + 1) >> 1);
340
 
                while (n-- > 0) {
341
 
                        *ptr = *hptr;
342
 
                        ptr += twostep;
343
 
                        hptr += step;
344
 
                }
345
 
                /* Copy the appropriate samples into the second phase of
346
 
                  the output signal. */
347
 
                ptr -= (lendind > hendind) ? (step) : (step + twostep);
348
 
                state = !((llen - 1) & 1);
349
 
                lptr = &lstartptr[(llen - 1) * step];
350
 
                n = llen;
351
 
                while (n-- > 0) {
352
 
                        if (state) {
353
 
                                --tmpptr;
354
 
                                *ptr = *tmpptr;
355
 
                        } else {
356
 
                                *ptr = *lptr;
357
 
                        }
358
 
                        lptr -= step;
359
 
                        ptr -= twostep;
360
 
                        state ^= 1;
361
 
                }
362
 
        } else {
363
 
                /* The first sample in the lowpass subband signal is to
364
 
                  appear first in the output signal. */
365
 
                /* Copy the appropriate samples into the first phase of the
366
 
                  output signal (corresponding to even indexed samples). */
367
 
                lptr = &lstartptr[(llen - 1) * step];
368
 
                ptr = &startptr[((llen - 1) << 1) * step];
369
 
                n = llen >> 1;
370
 
                tmpptr = buf;
371
 
                while (n-- > 0) {
372
 
                        *tmpptr = *ptr;
373
 
                        *ptr = *lptr;
374
 
                        ++tmpptr;
375
 
                        ptr -= twostep;
376
 
                        lptr -= step;
377
 
                }
378
 
                n = llen - (llen >> 1);
379
 
                while (n-- > 0) {
380
 
                        *ptr = *lptr;
381
 
                        ptr -= twostep;
382
 
                        lptr -= step;
383
 
                }
384
 
                /* Copy the appropriate samples into the second phase of
385
 
                  the output signal (corresponding to odd indexed
386
 
                  samples). */
387
 
                ptr = &startptr[step];
388
 
                hptr = hstartptr;
389
 
                state = !(llen & 1);
390
 
                n = hlen;
391
 
                while (n-- > 0) {
392
 
                        if (state) {
393
 
                                --tmpptr;
394
 
                                *ptr = *tmpptr;
395
 
                        } else {
396
 
                                *ptr = *hptr;
397
 
                        }
398
 
                        hptr += step;
399
 
                        ptr += twostep;
400
 
                        state ^= 1;
401
 
                }
402
 
        }
403
 
 
404
 
#if !defined(HAVE_VLA)
405
 
        /* If the join buffer was allocated on the heap, free this memory. */
406
 
        if (buf != joinbuf) {
407
 
                jas_free(buf);
408
 
        }
409
 
#endif
410
 
}
411
 
 
412
 
/******************************************************************************\
413
 
* Code for 5/3 transform.
414
 
\******************************************************************************/
415
 
 
416
 
static int jpc_ft_getnumchans(jpc_qmfb1d_t *qmfb)
417
 
{
418
 
        /* Avoid compiler warnings about unused parameters. */
419
 
        qmfb = 0;
420
 
 
421
 
        return 2;
422
 
}
423
 
 
424
 
static int jpc_ft_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
425
 
{
426
 
        /* Avoid compiler warnings about unused parameters. */
427
 
        qmfb = 0;
428
 
        len = 0;
429
 
        filters = 0;
430
 
 
431
 
        jas_error(      JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_FT_GETANALFILTERS,
432
 
                                "JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_FT_GETANALFILTERS"
433
 
                        );
434
 
        return -1;
435
 
}
436
 
 
437
 
static int jpc_ft_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
438
 
{
439
 
        jas_seq_t *lf;
440
 
        jas_seq_t *hf;
441
 
 
442
 
        /* Avoid compiler warnings about unused parameters. */
443
 
        qmfb = 0;
444
 
 
445
 
        lf = 0;
446
 
        hf = 0;
447
 
 
448
 
        if (len > 1 || (!len)) {
449
 
                if (!(lf = jas_seq_create(-1, 2))) {
450
 
                        goto error;
451
 
                }
452
 
                jas_seq_set(lf, -1, jpc_dbltofix(0.5));
453
 
                jas_seq_set(lf, 0, jpc_dbltofix(1.0));
454
 
                jas_seq_set(lf, 1, jpc_dbltofix(0.5));
455
 
                if (!(hf = jas_seq_create(-1, 4))) {
456
 
                        goto error;
457
 
                }
458
 
                jas_seq_set(hf, -1, jpc_dbltofix(-0.125));
459
 
                jas_seq_set(hf, 0, jpc_dbltofix(-0.25));
460
 
                jas_seq_set(hf, 1, jpc_dbltofix(0.75));
461
 
                jas_seq_set(hf, 2, jpc_dbltofix(-0.25));
462
 
                jas_seq_set(hf, 3, jpc_dbltofix(-0.125));
463
 
        } else if (len == 1) {
464
 
                if (!(lf = jas_seq_create(0, 1))) {
465
 
                        goto error;
466
 
                }
467
 
                jas_seq_set(lf, 0, jpc_dbltofix(1.0));
468
 
                if (!(hf = jas_seq_create(0, 1))) {
469
 
                        goto error;
470
 
                }
471
 
                jas_seq_set(hf, 0, jpc_dbltofix(2.0));
472
 
        } else {
473
 
                jas_error(      JAS_ERR_INVALID_LEN_PARAM_JPC_FT_GETSYNFILTERS,
474
 
                                        "JAS_ERR_INVALID_LEN_PARAM_JPC_FT_GETSYNFILTERS"
475
 
                                );
476
 
                goto error;
477
 
        }
478
 
 
479
 
        filters[0] = lf;
480
 
        filters[1] = hf;
481
 
 
482
 
        return 0;
483
 
 
484
 
error:
485
 
        if (lf) {
486
 
                jas_seq_destroy(lf);
487
 
        }
488
 
        if (hf) {
489
 
                jas_seq_destroy(hf);
490
 
        }
491
 
        return -1;
492
 
}
493
 
 
494
 
#define NFT_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pluseq) \
495
 
{ \
496
 
        register jpc_fix_t *lptr = (lstartptr); \
497
 
        register jpc_fix_t *hptr = (hstartptr); \
498
 
        register int n = (hendind) - (hstartind); \
499
 
        if ((hstartind) < (lstartind)) { \
500
 
                pluseq(*hptr, *lptr); \
501
 
                hptr += (step); \
502
 
                --n; \
503
 
        } \
504
 
        if ((hendind) >= (lendind)) { \
505
 
                --n; \
506
 
        } \
507
 
        while (n-- > 0) { \
508
 
                pluseq(*hptr, jpc_fix_asr(jpc_fix_add(*lptr, lptr[(step)]), 1)); \
509
 
                hptr += (step); \
510
 
                lptr += (step); \
511
 
        } \
512
 
        if ((hendind) >= (lendind)) { \
513
 
                pluseq(*hptr, *lptr); \
514
 
        } \
515
 
}
516
 
 
517
 
#define NFT_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pluseq) \
518
 
{ \
519
 
        register jpc_fix_t *lptr = (lstartptr); \
520
 
        register jpc_fix_t *hptr = (hstartptr); \
521
 
        register int n = (lendind) - (lstartind); \
522
 
        if ((hstartind) >= (lstartind)) { \
523
 
                pluseq(*lptr, *hptr); \
524
 
                lptr += (step); \
525
 
                --n; \
526
 
        } \
527
 
        if ((lendind) > (hendind)) { \
528
 
                --n; \
529
 
        } \
530
 
        while (n-- > 0) { \
531
 
                pluseq(*lptr, jpc_fix_asr(jpc_fix_add(*hptr, hptr[(step)]), 2)); \
532
 
                lptr += (step); \
533
 
                hptr += (step); \
534
 
        } \
535
 
        if ((lendind) > (hendind)) { \
536
 
                pluseq(*lptr, *hptr); \
537
 
        } \
538
 
}
539
 
 
540
 
#define RFT_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pmeqop) \
541
 
{ \
542
 
        register jpc_fix_t *lptr = (lstartptr); \
543
 
        register jpc_fix_t *hptr = (hstartptr); \
544
 
        register int n = (hendind) - (hstartind); \
545
 
        if ((hstartind) < (lstartind)) { \
546
 
                *hptr pmeqop *lptr; \
547
 
                hptr += (step); \
548
 
                --n; \
549
 
        } \
550
 
        if ((hendind) >= (lendind)) { \
551
 
                --n; \
552
 
        } \
553
 
        while (n-- > 0) { \
554
 
                *hptr pmeqop (*lptr + lptr[(step)]) >> 1; \
555
 
                hptr += (step); \
556
 
                lptr += (step); \
557
 
        } \
558
 
        if ((hendind) >= (lendind)) { \
559
 
                *hptr pmeqop *lptr; \
560
 
        } \
561
 
}
562
 
 
563
 
#define RFT_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pmeqop) \
564
 
{ \
565
 
        register jpc_fix_t *lptr = (lstartptr); \
566
 
        register jpc_fix_t *hptr = (hstartptr); \
567
 
        register int n = (lendind) - (lstartind); \
568
 
        if ((hstartind) >= (lstartind)) { \
569
 
                *lptr pmeqop ((*hptr << 1) + 2) >> 2; \
570
 
                lptr += (step); \
571
 
                --n; \
572
 
        } \
573
 
        if ((lendind) > (hendind)) { \
574
 
                --n; \
575
 
        } \
576
 
        while (n-- > 0) { \
577
 
                *lptr pmeqop ((*hptr + hptr[(step)]) + 2) >> 2; \
578
 
                lptr += (step); \
579
 
                hptr += (step); \
580
 
        } \
581
 
        if ((lendind) > (hendind)) { \
582
 
                *lptr pmeqop ((*hptr << 1) + 2) >> 2; \
583
 
        } \
584
 
}
585
 
 
586
 
static void jpc_ft_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
587
 
{
588
 
        jpc_fix_t *startptr;
589
 
        int startind;
590
 
        int endind;
591
 
        jpc_fix_t *  lstartptr;
592
 
        int   lstartind;
593
 
        int   lendind;
594
 
        jpc_fix_t *  hstartptr;
595
 
        int   hstartind;
596
 
        int   hendind;
597
 
        int interstep;
598
 
        int intrastep;
599
 
        int numseq;
600
 
 
601
 
        /* Avoid compiler warnings about unused parameters. */
602
 
        qmfb = 0;
603
 
 
604
 
        if (flags & JPC_QMFB1D_VERT) {
605
 
                interstep = 1;
606
 
                intrastep = jas_seq2d_rowstep(x);
607
 
                numseq = jas_seq2d_width(x);
608
 
                startind = jas_seq2d_ystart(x);
609
 
                endind = jas_seq2d_yend(x);
610
 
        } else {
611
 
                interstep = jas_seq2d_rowstep(x);
612
 
                intrastep = 1;
613
 
                numseq = jas_seq2d_height(x);
614
 
                startind = jas_seq2d_xstart(x);
615
 
                endind = jas_seq2d_xend(x);
616
 
        }
617
 
 
618
 
        assert(startind < endind);
619
 
 
620
 
        startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
621
 
        if (flags & JPC_QMFB1D_RITIMODE) {
622
 
                while (numseq-- > 0) {
623
 
                        jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
624
 
                          &lstartptr, &lstartind, &lendind, &hstartptr,
625
 
                          &hstartind, &hendind);
626
 
                        if (endind - startind > 1) {
627
 
                                jpc_qmfb1d_split(startptr, startind, endind,
628
 
                                  intrastep, lstartptr, lstartind, lendind,
629
 
                                  hstartptr, hstartind, hendind);
630
 
                                RFT_LIFT0(lstartptr, lstartind, lendind,
631
 
                                  hstartptr, hstartind, hendind, intrastep, -=);
632
 
                                RFT_LIFT1(lstartptr, lstartind, lendind,
633
 
                                  hstartptr, hstartind, hendind, intrastep, +=);
634
 
                        } else {
635
 
                                if (lstartind == lendind) {
636
 
                                        *startptr <<= 1;
637
 
                                }
638
 
                        }
639
 
                        startptr += interstep;
640
 
                }
641
 
        } else {
642
 
                while (numseq-- > 0) {
643
 
                        jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
644
 
                          &lstartptr, &lstartind, &lendind, &hstartptr,
645
 
                          &hstartind, &hendind);
646
 
                        if (endind - startind > 1) {
647
 
                                jpc_qmfb1d_split(startptr, startind, endind,
648
 
                                  intrastep, lstartptr, lstartind, lendind,
649
 
                                  hstartptr, hstartind, hendind);
650
 
                                NFT_LIFT0(lstartptr, lstartind, lendind,
651
 
                                  hstartptr, hstartind, hendind, intrastep,
652
 
                                  jpc_fix_minuseq);
653
 
                                NFT_LIFT1(lstartptr, lstartind, lendind,
654
 
                                  hstartptr, hstartind, hendind, intrastep,
655
 
                                  jpc_fix_pluseq);
656
 
                        } else {
657
 
                                if (lstartind == lendind) {
658
 
                                        *startptr = jpc_fix_asl(*startptr, 1);
659
 
                                }
660
 
                        }
661
 
                        startptr += interstep;
662
 
                }
663
 
        }
664
 
}
665
 
 
666
 
static void jpc_ft_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
667
 
{
668
 
        jpc_fix_t *startptr;
669
 
        int startind;
670
 
        int endind;
671
 
        jpc_fix_t *lstartptr;
672
 
        int lstartind;
673
 
        int lendind;
674
 
        jpc_fix_t *hstartptr;
675
 
        int hstartind;
676
 
        int hendind;
677
 
        int interstep;
678
 
        int intrastep;
679
 
        int numseq;
680
 
 
681
 
        /* Avoid compiler warnings about unused parameters. */
682
 
        qmfb = 0;
683
 
 
684
 
        if (flags & JPC_QMFB1D_VERT) {
685
 
                interstep = 1;
686
 
                intrastep = jas_seq2d_rowstep(x);
687
 
                numseq = jas_seq2d_width(x);
688
 
                startind = jas_seq2d_ystart(x);
689
 
                endind = jas_seq2d_yend(x);
690
 
        } else {
691
 
                interstep = jas_seq2d_rowstep(x);
692
 
                intrastep = 1;
693
 
                numseq = jas_seq2d_height(x);
694
 
                startind = jas_seq2d_xstart(x);
695
 
                endind = jas_seq2d_xend(x);
696
 
        }
697
 
 
698
 
        assert(startind < endind);
699
 
 
700
 
        startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
701
 
        if (flags & JPC_QMFB1D_RITIMODE) {
702
 
                while (numseq-- > 0) {
703
 
                        jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
704
 
                          &lstartptr, &lstartind, &lendind, &hstartptr,
705
 
                          &hstartind, &hendind);
706
 
                        if (endind - startind > 1) {
707
 
                                RFT_LIFT1(lstartptr, lstartind, lendind,
708
 
                                  hstartptr, hstartind, hendind, intrastep, -=);
709
 
                                RFT_LIFT0(lstartptr, lstartind, lendind,
710
 
                                  hstartptr, hstartind, hendind, intrastep, +=);
711
 
                                jpc_qmfb1d_join(startptr, startind, endind,
712
 
                                  intrastep, lstartptr, lstartind, lendind,
713
 
                                  hstartptr, hstartind, hendind);
714
 
                        } else {
715
 
                                if (lstartind == lendind) {
716
 
                                        *startptr >>= 1;
717
 
                                }
718
 
                        }
719
 
                        startptr += interstep;
720
 
                }
721
 
        } else {
722
 
                while (numseq-- > 0) {
723
 
                        jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
724
 
                          &lstartptr, &lstartind, &lendind, &hstartptr,
725
 
                          &hstartind, &hendind);
726
 
                        if (endind - startind > 1) {
727
 
                                NFT_LIFT1(lstartptr, lstartind, lendind,
728
 
                                  hstartptr, hstartind, hendind, intrastep,
729
 
                                  jpc_fix_minuseq);
730
 
                                NFT_LIFT0(lstartptr, lstartind, lendind,
731
 
                                  hstartptr, hstartind, hendind, intrastep,
732
 
                                  jpc_fix_pluseq);
733
 
                                jpc_qmfb1d_join(startptr, startind, endind,
734
 
                                  intrastep, lstartptr, lstartind, lendind,
735
 
                                  hstartptr, hstartind, hendind);
736
 
                        } else {
737
 
                                if (lstartind == lendind) {
738
 
                                        *startptr = jpc_fix_asr(*startptr, 1);
739
 
                                }
740
 
                        }
741
 
                        startptr += interstep;
742
 
                }
743
 
        }
744
 
}
745
 
 
746
 
/******************************************************************************\
747
 
* Code for 9/7 transform.
748
 
\******************************************************************************/
749
 
 
750
 
static int jpc_ns_getnumchans(jpc_qmfb1d_t *qmfb)
751
 
{
752
 
        /* Avoid compiler warnings about unused parameters. */
753
 
        qmfb = 0;
754
 
 
755
 
        return 2;
756
 
}
757
 
 
758
 
static int jpc_ns_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
759
 
{
760
 
        /* Avoid compiler warnings about unused parameters. */
761
 
        qmfb = 0;
762
 
        len = 0;
763
 
        filters = 0;
764
 
 
765
 
        jas_error(      JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_NS_GETANALFILTERS,
766
 
                                "JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_NS_GETANALFILTERS"
767
 
                        );
768
 
        return -1;
769
 
}
770
 
 
771
 
static int jpc_ns_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
772
 
{
773
 
        jas_seq_t *lf;
774
 
        jas_seq_t *hf;
775
 
 
776
 
        /* Avoid compiler warnings about unused parameters. */
777
 
        qmfb = 0;
778
 
 
779
 
        lf = 0;
780
 
        hf = 0;
781
 
 
782
 
        if (len > 1 || (!len)) {
783
 
                if (!(lf = jas_seq_create(-3, 4))) {
784
 
                        goto error;
785
 
                }
786
 
                jas_seq_set(lf, -3, jpc_dbltofix(-0.09127176311424948));
787
 
                jas_seq_set(lf, -2, jpc_dbltofix(-0.05754352622849957));
788
 
                jas_seq_set(lf, -1, jpc_dbltofix(0.5912717631142470));
789
 
                jas_seq_set(lf, 0, jpc_dbltofix(1.115087052456994));
790
 
                jas_seq_set(lf, 1, jpc_dbltofix(0.5912717631142470));
791
 
                jas_seq_set(lf, 2, jpc_dbltofix(-0.05754352622849957));
792
 
                jas_seq_set(lf, 3, jpc_dbltofix(-0.09127176311424948));
793
 
                if (!(hf = jas_seq_create(-3, 6))) {
794
 
                        goto error;
795
 
                }
796
 
                jas_seq_set(hf, -3, jpc_dbltofix(-0.02674875741080976 * 2.0));
797
 
                jas_seq_set(hf, -2, jpc_dbltofix(-0.01686411844287495 * 2.0));
798
 
                jas_seq_set(hf, -1, jpc_dbltofix(0.07822326652898785 * 2.0));
799
 
                jas_seq_set(hf, 0, jpc_dbltofix(0.2668641184428723 * 2.0));
800
 
                jas_seq_set(hf, 1, jpc_dbltofix(-0.6029490182363579 * 2.0));
801
 
                jas_seq_set(hf, 2, jpc_dbltofix(0.2668641184428723 * 2.0));
802
 
                jas_seq_set(hf, 3, jpc_dbltofix(0.07822326652898785 * 2.0));
803
 
                jas_seq_set(hf, 4, jpc_dbltofix(-0.01686411844287495 * 2.0));
804
 
                jas_seq_set(hf, 5, jpc_dbltofix(-0.02674875741080976 * 2.0));
805
 
        } else if (len == 1) {
806
 
                if (!(lf = jas_seq_create(0, 1))) {
807
 
                        goto error;
808
 
                }
809
 
                jas_seq_set(lf, 0, jpc_dbltofix(1.0));
810
 
                if (!(hf = jas_seq_create(0, 1))) {
811
 
                        goto error;
812
 
                }
813
 
                jas_seq_set(hf, 0, jpc_dbltofix(2.0));
814
 
        } else {
815
 
                jas_error(      JAS_ERR_INVALID_LEN_PARAM_JPC_NS_GETSYNFILTERS,
816
 
                                        "JAS_ERR_INVALID_LEN_PARAM_JPC_NS_GETSYNFILTERS"
817
 
                                );
818
 
                goto error;
819
 
        }
820
 
 
821
 
        filters[0] = lf;
822
 
        filters[1] = hf;
823
 
 
824
 
        return 0;
825
 
 
826
 
error:
827
 
        if (lf) {
828
 
                jas_seq_destroy(lf);
829
 
        }
830
 
        if (hf) {
831
 
                jas_seq_destroy(hf);
832
 
        }
833
 
        return -1;
834
 
}
835
 
 
836
 
#define NNS_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \
837
 
{ \
838
 
        register jpc_fix_t *lptr = (lstartptr); \
839
 
        register jpc_fix_t *hptr = (hstartptr); \
840
 
        register int n = (hendind) - (hstartind); \
841
 
        jpc_fix_t twoalpha = jpc_fix_mulbyint(alpha, 2); \
842
 
        if ((hstartind) < (lstartind)) { \
843
 
                jpc_fix_pluseq(*hptr, jpc_fix_mul(*lptr, (twoalpha))); \
844
 
                hptr += (step); \
845
 
                --n; \
846
 
        } \
847
 
        if ((hendind) >= (lendind)) { \
848
 
                --n; \
849
 
        } \
850
 
        while (n-- > 0) { \
851
 
                jpc_fix_pluseq(*hptr, jpc_fix_mul(jpc_fix_add(*lptr, lptr[(step)]), (alpha))); \
852
 
                hptr += (step); \
853
 
                lptr += (step); \
854
 
        } \
855
 
        if ((hendind) >= (lendind)) { \
856
 
                jpc_fix_pluseq(*hptr, jpc_fix_mul(*lptr, (twoalpha))); \
857
 
        } \
858
 
}
859
 
 
860
 
#define NNS_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \
861
 
{ \
862
 
        register jpc_fix_t *lptr = (lstartptr); \
863
 
        register jpc_fix_t *hptr = (hstartptr); \
864
 
        register int n = (lendind) - (lstartind); \
865
 
        int twoalpha = jpc_fix_mulbyint(alpha, 2); \
866
 
        if ((hstartind) >= (lstartind)) { \
867
 
                jpc_fix_pluseq(*lptr, jpc_fix_mul(*hptr, (twoalpha))); \
868
 
                lptr += (step); \
869
 
                --n; \
870
 
        } \
871
 
        if ((lendind) > (hendind)) { \
872
 
                --n; \
873
 
        } \
874
 
        while (n-- > 0) { \
875
 
                jpc_fix_pluseq(*lptr, jpc_fix_mul(jpc_fix_add(*hptr, hptr[(step)]), (alpha))); \
876
 
                lptr += (step); \
877
 
                hptr += (step); \
878
 
        } \
879
 
        if ((lendind) > (hendind)) { \
880
 
                jpc_fix_pluseq(*lptr, jpc_fix_mul(*hptr, (twoalpha))); \
881
 
        } \
882
 
}
883
 
 
884
 
#define NNS_SCALE(startptr, startind, endind, step, alpha) \
885
 
{ \
886
 
        register jpc_fix_t *ptr = (startptr); \
887
 
        register int n = (endind) - (startind); \
888
 
        while (n-- > 0) { \
889
 
                jpc_fix_muleq(*ptr, alpha); \
890
 
                ptr += (step); \
891
 
        } \
892
 
}
893
 
 
894
 
static void jpc_ns_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
895
 
{
896
 
        jpc_fix_t *startptr;
897
 
        int startind;
898
 
        int endind;
899
 
        jpc_fix_t *lstartptr;
900
 
        int lstartind;
901
 
        int lendind;
902
 
        jpc_fix_t *hstartptr;
903
 
        int hstartind;
904
 
        int hendind;
905
 
        int interstep;
906
 
        int intrastep;
907
 
        int numseq;
908
 
 
909
 
        /* Avoid compiler warnings about unused parameters. */
910
 
        qmfb = 0;
911
 
 
912
 
        if (flags & JPC_QMFB1D_VERT) {
913
 
                interstep = 1;
914
 
                intrastep = jas_seq2d_rowstep(x);
915
 
                numseq = jas_seq2d_width(x);
916
 
                startind = jas_seq2d_ystart(x);
917
 
                endind = jas_seq2d_yend(x);
918
 
        } else {
919
 
                interstep = jas_seq2d_rowstep(x);
920
 
                intrastep = 1;
921
 
                numseq = jas_seq2d_height(x);
922
 
                startind = jas_seq2d_xstart(x);
923
 
                endind = jas_seq2d_xend(x);
924
 
        }
925
 
 
926
 
        assert(startind < endind);
927
 
 
928
 
        startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
929
 
        if (!(flags & JPC_QMFB1D_RITIMODE)) {
930
 
                while (numseq-- > 0) {
931
 
                        jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
932
 
                          &lstartptr, &lstartind, &lendind, &hstartptr,
933
 
                          &hstartind, &hendind);
934
 
                        if (endind - startind > 1) {
935
 
                                jpc_qmfb1d_split(startptr, startind, endind,
936
 
                                  intrastep, lstartptr, lstartind, lendind,
937
 
                                  hstartptr, hstartind, hendind);
938
 
                                NNS_LIFT0(lstartptr, lstartind, lendind,
939
 
                                  hstartptr, hstartind, hendind, intrastep,
940
 
                                  jpc_dbltofix(-1.586134342));
941
 
                                NNS_LIFT1(lstartptr, lstartind, lendind,
942
 
                                  hstartptr, hstartind, hendind, intrastep,
943
 
                                  jpc_dbltofix(-0.052980118));
944
 
                                NNS_LIFT0(lstartptr, lstartind, lendind,
945
 
                                  hstartptr, hstartind, hendind, intrastep,
946
 
                                  jpc_dbltofix(0.882911075));
947
 
                                NNS_LIFT1(lstartptr, lstartind, lendind,
948
 
                                  hstartptr, hstartind, hendind, intrastep,
949
 
                                  jpc_dbltofix(0.443506852));
950
 
                                NNS_SCALE(lstartptr, lstartind, lendind,
951
 
                                  intrastep, jpc_dbltofix(1.0/1.23017410558578));
952
 
                                NNS_SCALE(hstartptr, hstartind, hendind,
953
 
                                  intrastep, jpc_dbltofix(1.0/1.62578613134411));
954
 
                        } else {
955
 
#if 0
956
 
                                if (lstartind == lendind) {
957
 
                                        *startptr = jpc_fix_asl(*startptr, 1);
958
 
                                }
959
 
#endif
960
 
                        }
961
 
                        startptr += interstep;
962
 
                }
963
 
        } else {
964
 
                /* The reversible integer-to-integer mode is not supported
965
 
                  for this transform. */
966
 
                jas_error(      JAS_ERR_UNSUPPORTED_MODE_JPC_NS_ANALYZE,
967
 
                                        "JAS_ERR_UNSUPPORTED_MODE_JPC_NS_ANALYZE"
968
 
                                );
969
 
        }
970
 
}
971
 
 
972
 
 
973
 
#ifdef USE_ASM_WIN32
974
 
 
975
 
#define DBL_FIX_A       (0x0000275d)
976
 
#define DBL_FIX_B       (0x00003406)
977
 
#define DBL_FIX_C       (0xfffff1cf)
978
 
#define DBL_FIX_D       (0xffffe3c0)
979
 
#define DBL_FIX_E       (0x000001b2)
980
 
#define DBL_FIX_F       (0x000032c1)
981
 
 
982
 
#define twoalpha_C      (0xffffe39e)
983
 
#define twoalpha_D      (0xffffc780)
984
 
#define twoalpha_E      (0x00000364)
985
 
#define twoalpha_F      (0x00006582)
986
 
 
987
 
#endif
988
 
 
989
 
 
990
 
 
991
 
 
992
 
void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
993
 
{
994
 
        jpc_fix_t *startptr;
995
 
        int startind;
996
 
        int endind;
997
 
        jpc_fix_t *lstartptr;
998
 
        int lstartind;
999
 
        int lendind;
1000
 
        jpc_fix_t *hstartptr;
1001
 
        int hstartind;
1002
 
        int hendind;
1003
 
        int interstep;
1004
 
        int intrastep;
1005
 
        int numseq;
1006
 
 
1007
 
        /* Avoid compiler warnings about unused parameters. */
1008
 
        qmfb = 0;
1009
 
 
1010
 
        if (flags & JPC_QMFB1D_VERT) {
1011
 
                interstep = 1;
1012
 
                intrastep = jas_seq2d_rowstep(x);
1013
 
                numseq = jas_seq2d_width(x);
1014
 
                startind = jas_seq2d_ystart(x);
1015
 
                endind = jas_seq2d_yend(x);
1016
 
        } else {
1017
 
                interstep = jas_seq2d_rowstep(x);
1018
 
                intrastep = 1;
1019
 
                numseq = jas_seq2d_height(x);
1020
 
                startind = jas_seq2d_xstart(x);
1021
 
                endind = jas_seq2d_xend(x);
1022
 
        }
1023
 
 
1024
 
        assert(startind < endind);
1025
 
 
1026
 
        startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
1027
 
        if (!(flags & JPC_QMFB1D_RITIMODE)) {
1028
 
                while (numseq-- > 0) {
1029
 
                        jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
1030
 
                          &lstartptr, &lstartind, &lendind, &hstartptr,
1031
 
                          &hstartind, &hendind);
1032
 
                        if (endind - startind > 1) {
1033
 
                                NNS_SCALE(lstartptr, lstartind, lendind,
1034
 
                                  intrastep, jpc_dbltofix(1.23017410558578));
1035
 
                                NNS_SCALE(hstartptr, hstartind, hendind,
1036
 
                                  intrastep, jpc_dbltofix(1.62578613134411));
1037
 
                                NNS_LIFT1(lstartptr, lstartind, lendind,
1038
 
                                  hstartptr, hstartind, hendind, intrastep,
1039
 
                                  jpc_dbltofix(-0.443506852));
1040
 
                                NNS_LIFT0(lstartptr, lstartind, lendind,
1041
 
                                  hstartptr, hstartind, hendind, intrastep,
1042
 
                                  jpc_dbltofix(-0.882911075));
1043
 
                                NNS_LIFT1(lstartptr, lstartind, lendind,
1044
 
                                  hstartptr, hstartind, hendind, intrastep,
1045
 
                                  jpc_dbltofix(0.052980118));
1046
 
                                NNS_LIFT0(lstartptr, lstartind, lendind,
1047
 
                                  hstartptr, hstartind, hendind, intrastep,
1048
 
                                  jpc_dbltofix(1.586134342));
1049
 
                                jpc_qmfb1d_join(startptr, startind, endind,
1050
 
                                  intrastep, lstartptr, lstartind, lendind,
1051
 
                                  hstartptr, hstartind, hendind);
1052
 
                        } else {
1053
 
#if 0
1054
 
                                if (lstartind == lendind) {
1055
 
                                        *startptr = jpc_fix_asr(*startptr, 1);
1056
 
                                }
1057
 
#endif
1058
 
                        }
1059
 
                        startptr += interstep;
1060
 
                }
1061
 
        } else {
1062
 
                /* The reversible integer-to-integer mode is not supported
1063
 
                  for this transform. */
1064
 
                jas_error(      JAS_ERR_UNSUPPORTED_MODE_JPC_NS_SYNTHESIZE,
1065
 
                                        "JAS_ERR_UNSUPPORTED_MODE_JPC_NS_SYNTHESIZE"
1066
 
                                );
1067
 
        }
1068
 
}
1069
 
 
1070
 
 
1071
 
 
1072
 
#ifdef USE_ASM_WIN32
1073
 
 
1074
 
 
1075
 
#define USE_LF_ASM
1076
 
 
1077
 
void jpc_win32_ns_synthesize(   jpc_qmfb1d_t *qmfb, 
1078
 
                                                                int flags, 
1079
 
                                                                jas_seq2d_t *x
1080
 
                                                        )
1081
 
{
1082
 
        jpc_fix_t *startptr;
1083
 
        int startind;
1084
 
        int endind;
1085
 
        jpc_fix_t *lstartptr;
1086
 
        int lstartind;
1087
 
        int lendind;
1088
 
        jpc_fix_t *hstartptr;
1089
 
        int hstartind;
1090
 
        int hendind;
1091
 
        int interstep;
1092
 
        int intrastep;
1093
 
        int numseq;
1094
 
 
1095
 
        /* Avoid compiler warnings about unused parameters. */
1096
 
        qmfb = 0;
1097
 
 
1098
 
        if (flags & JPC_QMFB1D_VERT) 
1099
 
        {
1100
 
                interstep = 1;
1101
 
                intrastep = jas_seq2d_rowstep(x);
1102
 
                numseq = jas_seq2d_width(x);
1103
 
                startind = jas_seq2d_ystart(x);
1104
 
                endind = jas_seq2d_yend(x);
1105
 
        } 
1106
 
        else 
1107
 
        {
1108
 
                interstep = jas_seq2d_rowstep(x);
1109
 
                intrastep = 1;
1110
 
                numseq = jas_seq2d_height(x);
1111
 
                startind = jas_seq2d_xstart(x);
1112
 
                endind = jas_seq2d_xend(x);
1113
 
        }
1114
 
 
1115
 
        assert(startind < endind);
1116
 
 
1117
 
        startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
1118
 
 
1119
 
        if (!(flags & JPC_QMFB1D_RITIMODE)) 
1120
 
        {
1121
 
                while (numseq-- > 0) 
1122
 
                {
1123
 
                        jpc_qmfb1d_setup(       startptr, 
1124
 
                                                                startind, 
1125
 
                                                                endind, 
1126
 
                                                                intrastep,
1127
 
                                                                &lstartptr, 
1128
 
                                                                &lstartind, 
1129
 
                                                                &lendind, 
1130
 
                                                                &hstartptr,
1131
 
                                                                &hstartind, 
1132
 
                                                                &hendind
1133
 
                                                        );
1134
 
 
1135
 
                        if (endind - startind > 1) 
1136
 
                        {
1137
 
#if !defined(USE_LF_ASM)
1138
 
                                NNS_SCALE(      lstartptr, 
1139
 
                                                        lstartind, 
1140
 
                                                        lendind,
1141
 
                                                        intrastep, 
1142
 
                                                        DBL_FIX_A
1143
 
                                                );
1144
 
#else
1145
 
 
1146
 
        __asm   mov     esi,    lstartptr
1147
 
        __asm   mov     eax,    lstartind
1148
 
        __asm   mov ebx,        lendind
1149
 
        __asm   sub ebx,        eax
1150
 
        __asm   mov                     ecx, intrastep
1151
 
        __asm   shl                     ecx, 2
1152
 
 
1153
 
scale_lp0:      ;
1154
 
        __asm   test    ebx, ebx
1155
 
        __asm   je              skip_scale0
1156
 
 
1157
 
        __asm   mov             eax, [esi]
1158
 
        __asm   test    eax, eax
1159
 
        __asm   je              skip_mul0
1160
 
        __asm   mov             edx, DBL_FIX_A
1161
 
        __asm   imul    edx
1162
 
        __asm   shrd    eax, edx, JPC_FIX_FRACBITS
1163
 
        __asm   mov             [esi], eax
1164
 
skip_mul0:      ;
1165
 
        __asm   add             esi, ecx
1166
 
        __asm   sub             ebx, 1
1167
 
        __asm   jmp             scale_lp0
1168
 
skip_scale0:    ;
1169
 
 
1170
 
#endif
1171
 
 
1172
 
#if !defined(USE_LF_ASM)
1173
 
                                NNS_SCALE(      hstartptr, 
1174
 
                                                        hstartind, 
1175
 
                                                        hendind,
1176
 
                                                        intrastep, 
1177
 
                                                        DBL_FIX_B
1178
 
                                                );
1179
 
#else
1180
 
 
1181
 
        __asm   mov     esi,    hstartptr
1182
 
        __asm   mov     eax,    hstartind
1183
 
        __asm   mov ebx,        hendind
1184
 
        __asm   sub ebx,        eax
1185
 
 
1186
 
scale_lp1:      ;
1187
 
        __asm   test    ebx, ebx
1188
 
        __asm   je              skip_scale1
1189
 
 
1190
 
        __asm   mov             eax, [esi]
1191
 
        __asm   test    eax, eax
1192
 
        __asm   je              skip_mul1
1193
 
        __asm   mov             edx, DBL_FIX_B
1194
 
        __asm   imul    edx
1195
 
        __asm   shrd    eax, edx, JPC_FIX_FRACBITS
1196
 
        __asm   mov             [esi], eax
1197
 
skip_mul1:      ;
1198
 
        __asm   add             esi, ecx
1199
 
        __asm   sub             ebx, 1
1200
 
        __asm   jmp             scale_lp1
1201
 
skip_scale1:    ;
1202
 
 
1203
 
#endif
1204
 
 
1205
 
#if !defined(USE_LF_ASM)
1206
 
                                RA_NNS_LIFT1(   lstartptr, 
1207
 
                                                                lstartind, 
1208
 
                                                                lendind,
1209
 
                                                                hstartptr, 
1210
 
                                                                hstartind, 
1211
 
                                                                hendind, 
1212
 
                                                                intrastep,
1213
 
                                                                DBL_FIX_C,
1214
 
                                                                twoalpha_C
1215
 
                                                        );
1216
 
#else
1217
 
 
1218
 
        __asm   mov     esi,    lstartptr
1219
 
        __asm   mov     edi,    hstartptr
1220
 
        __asm   mov     eax,    lstartind
1221
 
        __asm   mov ebx,        lendind
1222
 
        __asm   sub ebx,        eax
1223
 
 
1224
 
        __asm   mov     eax,    hstartind
1225
 
        __asm   cmp     eax,    lstartind
1226
 
        __asm   jl                      no_1C
1227
 
        
1228
 
        __asm   mov                     eax, [edi]
1229
 
        __asm   test            eax, eax
1230
 
        __asm   je                      skip_slow1C
1231
 
        __asm   mov                     edx, twoalpha_C
1232
 
        __asm   imul            edx
1233
 
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
1234
 
        __asm   add                     dword ptr[esi], eax
1235
 
skip_slow1C:
1236
 
 
1237
 
        __asm   add                     esi, ecx
1238
 
        __asm   sub                     ebx, 1
1239
 
no_1C:
1240
 
        __asm   mov     eax,    lendind
1241
 
        __asm   cmp     eax,    hendind
1242
 
        __asm   jle                     lpC
1243
 
        __asm   sub                     ebx, 1
1244
 
 
1245
 
lpC:
1246
 
        __asm   test    ebx, ebx
1247
 
        __asm   jle             done_lpC
1248
 
lpaC:
1249
 
        __asm   mov             eax, dword ptr[edi]
1250
 
        __asm   sub             ebx, 1
1251
 
        __asm   add             eax, dword ptr[edi + ecx ]
1252
 
        __asm   test    eax, eax
1253
 
        __asm   je              skip_slowC
1254
 
 
1255
 
        __asm   mov             edx, DBL_FIX_C
1256
 
        __asm   imul    edx
1257
 
        __asm   shrd    eax, edx, JPC_FIX_FRACBITS
1258
 
        __asm   add             dword ptr[esi], eax
1259
 
 
1260
 
skip_slowC:
1261
 
        __asm   add             esi, ecx
1262
 
        __asm   add             edi, ecx
1263
 
        __asm   test    ebx, ebx
1264
 
        __asm   jg              lpaC
1265
 
done_lpC:                                       ;
1266
 
 
1267
 
        __asm   mov     eax,    lendind
1268
 
        __asm   cmp     eax,    hendind
1269
 
        __asm   jle                     no_3C
1270
 
        __asm   mov                     eax, dword ptr[edi]
1271
 
        __asm   test            eax, eax
1272
 
        __asm   je                      no_3C
1273
 
        __asm   mov                     edx, dword ptr[twoalpha_C]
1274
 
        __asm   imul            edx
1275
 
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
1276
 
        __asm   add                     dword ptr[esi],eax
1277
 
no_3C:          ;
1278
 
 
1279
 
#endif
1280
 
 
1281
 
 
1282
 
#if !defined(USE_LF_ASM)
1283
 
                                NNS_LIFT0(      lstartptr, 
1284
 
                                                        lstartind, 
1285
 
                                                        lendind,
1286
 
                                                        hstartptr, 
1287
 
                                                        hstartind, 
1288
 
                                                        hendind, 
1289
 
                                                        intrastep,
1290
 
                                                        DBL_FIX_D
1291
 
                                                );
1292
 
#else
1293
 
 
1294
 
        __asm   mov     esi,    lstartptr
1295
 
        __asm   mov     edi,    hstartptr
1296
 
        __asm   mov     eax,    hstartind
1297
 
        __asm   mov ebx,        hendind
1298
 
        __asm   sub ebx,        eax
1299
 
 
1300
 
        __asm   mov     eax,    hstartind
1301
 
        __asm   cmp     eax,    lstartind
1302
 
        __asm   jge                     no_lift0a
1303
 
        
1304
 
        __asm   mov                     eax, [edi]
1305
 
        __asm   test            eax, eax
1306
 
        __asm   je                      skip_slow_lift0
1307
 
        __asm   mov                     edx, twoalpha_D
1308
 
        __asm   imul            edx
1309
 
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
1310
 
        __asm   add                     dword ptr[esi], eax
1311
 
skip_slow_lift0:
1312
 
 
1313
 
        __asm   add                     esi, ecx
1314
 
        __asm   sub                     ebx, 1
1315
 
no_lift0a:
1316
 
 
1317
 
        __asm   mov     eax,    hendind
1318
 
        __asm   cmp     eax,    lendind
1319
 
        __asm   jl                      lpa_lift0
1320
 
        __asm   dec                     ebx
1321
 
 
1322
 
lpa_lift0:      ;
1323
 
        __asm   test    ebx, ebx
1324
 
        __asm   jle             done_lpa_lift0
1325
 
lpb_lift0:
1326
 
        __asm   mov             eax, dword ptr[esi]
1327
 
        __asm   sub             ebx, 1
1328
 
        __asm   add             eax, dword ptr[esi + ecx ]
1329
 
        __asm   test    eax, eax
1330
 
        __asm   je              skip_slowa_lift0
1331
 
 
1332
 
        __asm   mov             edx, DBL_FIX_D
1333
 
        __asm   imul    edx
1334
 
        __asm   shrd    eax, edx, JPC_FIX_FRACBITS
1335
 
        __asm   add             dword ptr[edi], eax
1336
 
 
1337
 
skip_slowa_lift0:
1338
 
        __asm   add             esi, ecx
1339
 
        __asm   add             edi, ecx
1340
 
        __asm   test    ebx, ebx
1341
 
        __asm   jg              lpb_lift0
1342
 
done_lpa_lift0: ;
1343
 
 
1344
 
        __asm   mov     eax,    hendind
1345
 
        __asm   cmp     eax,    lendind
1346
 
        __asm   jl                      no_3b_lift0
1347
 
        __asm   mov                     eax, dword ptr[esi]
1348
 
        __asm   test            eax, eax
1349
 
        __asm   je                      no_3b_lift0
1350
 
        __asm   mov                     edx, twoalpha_D
1351
 
        __asm   imul            edx
1352
 
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
1353
 
        __asm   add                     dword ptr[edi],eax
1354
 
no_3b_lift0:            ;
1355
 
 
1356
 
 
1357
 
#endif
1358
 
 
1359
 
#if !defined(USE_LF_ASM)
1360
 
                                NNS_LIFT1(      lstartptr, 
1361
 
                                                        lstartind, 
1362
 
                                                        lendind,
1363
 
                                                        hstartptr, 
1364
 
                                                        hstartind, 
1365
 
                                                        hendind, 
1366
 
                                                        intrastep,
1367
 
                                                        DBL_FIX_E
1368
 
                                                );
1369
 
#else
1370
 
 
1371
 
        __asm   mov     esi,    lstartptr
1372
 
        __asm   mov     edi,    hstartptr
1373
 
        __asm   mov     eax,    lstartind
1374
 
        __asm   mov ebx,        lendind
1375
 
        __asm   sub ebx,        eax
1376
 
 
1377
 
        __asm   mov     eax,    hstartind
1378
 
        __asm   cmp     eax,    lstartind
1379
 
        __asm   jl                      no_1a
1380
 
        
1381
 
        __asm   mov                     eax, [edi]
1382
 
        __asm   test            eax, eax
1383
 
        __asm   je                      skip_slow1
1384
 
        __asm   mov                     edx, twoalpha_E
1385
 
        __asm   imul            edx
1386
 
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
1387
 
        __asm   add                     dword ptr[esi], eax
1388
 
skip_slow1:
1389
 
 
1390
 
        __asm   add                     esi, ecx
1391
 
        __asm   sub                     ebx, 1
1392
 
no_1a:
1393
 
        __asm   mov     eax,    lendind
1394
 
        __asm   cmp     eax,    hendind
1395
 
        __asm   jle                     lpa
1396
 
        __asm   sub                     ebx, 1
1397
 
 
1398
 
lpa:
1399
 
        __asm   test    ebx, ebx
1400
 
        __asm   jle             done_lpa
1401
 
lpaa:
1402
 
        __asm   mov             eax, dword ptr[edi]
1403
 
        __asm   sub             ebx, 1
1404
 
        __asm   add             eax, dword ptr[edi + ecx ]
1405
 
        __asm   test    eax, eax
1406
 
        __asm   je              skip_slow
1407
 
 
1408
 
        __asm   mov             edx, DBL_FIX_E
1409
 
        __asm   imul    edx
1410
 
        __asm   shrd    eax, edx, JPC_FIX_FRACBITS
1411
 
        __asm   add             dword ptr[esi], eax
1412
 
 
1413
 
skip_slow:
1414
 
        __asm   add             esi, ecx
1415
 
        __asm   add             edi, ecx
1416
 
        __asm   test    ebx, ebx
1417
 
        __asm   jg              lpaa
1418
 
done_lpa:                                                       ;
1419
 
 
1420
 
        __asm   mov     eax,    lendind
1421
 
        __asm   cmp     eax,    hendind
1422
 
        __asm   jle                     no_3a
1423
 
        __asm   mov                     eax, dword ptr[edi]
1424
 
        __asm   test            eax, eax
1425
 
        __asm   je                      no_3a
1426
 
        __asm   mov                     edx, dword ptr[twoalpha_E]
1427
 
        __asm   imul            edx
1428
 
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
1429
 
        __asm   add                     dword ptr[esi],eax
1430
 
no_3a:          ;
1431
 
#endif
1432
 
 
1433
 
 
1434
 
 
1435
 
#if !defined(USE_LF_ASM)
1436
 
                                NNS_LIFT0(      lstartptr, 
1437
 
                                                        lstartind, 
1438
 
                                                        lendind,
1439
 
                                                        hstartptr, 
1440
 
                                                        hstartind, 
1441
 
                                                        hendind, 
1442
 
                                                        intrastep,
1443
 
                                                        DBL_FIX_F
1444
 
                                                );
1445
 
#else
1446
 
 
1447
 
        __asm   mov     esi,    lstartptr
1448
 
        __asm   mov     edi,    hstartptr
1449
 
        __asm   mov     eax,    hstartind
1450
 
        __asm   mov ebx,        hendind
1451
 
        __asm   sub ebx,        eax
1452
 
 
1453
 
        __asm   mov     eax,    hstartind
1454
 
        __asm   cmp     eax,    lstartind
1455
 
        __asm   jge                     no_1d
1456
 
        
1457
 
        __asm   mov                     eax, [edi]
1458
 
        __asm   test            eax, eax
1459
 
        __asm   je                      skip_slow4
1460
 
        __asm   mov                     edx, twoalpha_F
1461
 
        __asm   imul            edx
1462
 
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
1463
 
        __asm   add                     dword ptr[esi], eax
1464
 
skip_slow4:
1465
 
 
1466
 
        __asm   add                     esi, ecx
1467
 
        __asm   sub                     ebx, 1
1468
 
no_1d:
1469
 
 
1470
 
        __asm   mov     eax,    hendind
1471
 
        __asm   cmp     eax,    lendind
1472
 
        __asm   jl                      lpd
1473
 
        __asm   dec                     ebx
1474
 
 
1475
 
lpd:    ;
1476
 
        __asm   test    ebx, ebx
1477
 
        __asm   jle             done_lpd
1478
 
lpad:
1479
 
        __asm   mov             eax, dword ptr[esi]
1480
 
        __asm   sub             ebx, 1
1481
 
        __asm   add             eax, dword ptr[esi + ecx ]
1482
 
        __asm   test    eax, eax
1483
 
        __asm   je              skip_slowd
1484
 
 
1485
 
        __asm   mov             edx, DBL_FIX_F
1486
 
        __asm   imul    edx
1487
 
        __asm   shrd    eax, edx, JPC_FIX_FRACBITS
1488
 
        __asm   add             dword ptr[edi], eax
1489
 
 
1490
 
skip_slowd:
1491
 
        __asm   add             esi, ecx
1492
 
        __asm   add             edi, ecx
1493
 
        __asm   test    ebx, ebx
1494
 
        __asm   jg              lpad
1495
 
done_lpd:       ;
1496
 
 
1497
 
        __asm   mov     eax,    hendind
1498
 
        __asm   cmp     eax,    lendind
1499
 
        __asm   jl                      no_3d
1500
 
        __asm   mov                     eax, dword ptr[esi]
1501
 
        __asm   test            eax, eax
1502
 
        __asm   je                      no_3d
1503
 
        __asm   mov                     edx, twoalpha_F
1504
 
        __asm   imul            edx
1505
 
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
1506
 
        __asm   add                     dword ptr[edi],eax
1507
 
no_3d:          ;
1508
 
#endif
1509
 
 
1510
 
 
1511
 
                                jpc_qmfb1d_join(        startptr, 
1512
 
                                                                        startind, 
1513
 
                                                                        endind,
1514
 
                                                                        intrastep, 
1515
 
                                                                        lstartptr, 
1516
 
                                                                        lstartind, 
1517
 
                                                                        lendind,
1518
 
                                                                        hstartptr, 
1519
 
                                                                        hstartind, 
1520
 
                                                                        hendind
1521
 
                                                                );
1522
 
                        } else 
1523
 
                        {
1524
 
#if !defined(USE_LF_ASM)
1525
 
                                if (lstartind == lendind) {
1526
 
                                        *startptr = jpc_fix_asr(*startptr, 1);
1527
 
                                }
1528
 
#endif
1529
 
                        }
1530
 
                        startptr += interstep;
1531
 
                }
1532
 
        } else {
1533
 
                /* The reversible integer-to-integer mode is not supported
1534
 
                  for this transform. */
1535
 
                jas_error(      JAS_ERR_UNSUPPORTED_MODE_JPC_NS_SYNTHESIZE,
1536
 
                                        "JAS_ERR_UNSUPPORTED_MODE_JPC_NS_SYNTHESIZE"
1537
 
                                );
1538
 
        }
1539
 
}
1540
 
 
1541
 
#endif
1542
 
 
1543
 
 
1544
 
/******************************************************************************\
1545
 
*
1546
 
\******************************************************************************/
1547
 
 
1548
 
jpc_qmfb1d_t *jpc_qmfb1d_make(int qmfbid)
1549
 
{
1550
 
        jpc_qmfb1d_t *qmfb;
1551
 
        if (!(qmfb = jpc_qmfb1d_create())) {
1552
 
                return 0;
1553
 
        }
1554
 
        switch (qmfbid) {
1555
 
        case JPC_QMFB1D_FT:
1556
 
                qmfb->ops = &jpc_ft_ops;
1557
 
                break;
1558
 
        case JPC_QMFB1D_NS:
1559
 
                qmfb->ops = &jpc_ns_ops;
1560
 
                break;
1561
 
        default:
1562
 
                jpc_qmfb1d_destroy(qmfb);
1563
 
                return 0;
1564
 
                break;
1565
 
        }
1566
 
        return qmfb;
1567
 
}
1568
 
 
1569
 
static jpc_qmfb1d_t *jpc_qmfb1d_create()
1570
 
{
1571
 
        jpc_qmfb1d_t *qmfb;
1572
 
        if (!(qmfb = jas_malloc(sizeof(jpc_qmfb1d_t)))) {
1573
 
                return 0;
1574
 
        }
1575
 
        qmfb->ops = 0;
1576
 
        return qmfb;
1577
 
}
1578
 
 
1579
 
jpc_qmfb1d_t *jpc_qmfb1d_copy(jpc_qmfb1d_t *qmfb)
1580
 
{
1581
 
        jpc_qmfb1d_t *newqmfb;
1582
 
 
1583
 
        if (!(newqmfb = jpc_qmfb1d_create())) {
1584
 
                return 0;
1585
 
        }
1586
 
        newqmfb->ops = qmfb->ops;
1587
 
        return newqmfb;
1588
 
}
1589
 
 
1590
 
void jpc_qmfb1d_destroy(jpc_qmfb1d_t *qmfb)
1591
 
{
1592
 
        jas_free(qmfb);
1593
 
}
1594
 
 
1595
 
/******************************************************************************\
1596
 
*
1597
 
\******************************************************************************/
1598
 
 
1599
 
void jpc_qmfb1d_getbands(jpc_qmfb1d_t *qmfb, int flags, uint_fast32_t xstart,
1600
 
  uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend, int maxbands,
1601
 
  int *numbandsptr, jpc_qmfb1dband_t *bands)
1602
 
{
1603
 
        int start;
1604
 
        int end;
1605
 
 
1606
 
        assert(maxbands >= 2);
1607
 
 
1608
 
        if (flags & JPC_QMFB1D_VERT) {
1609
 
                start = ystart;
1610
 
                end = yend;
1611
 
        } else {
1612
 
                start = xstart;
1613
 
                end = xend;
1614
 
        }
1615
 
/*      assert(jpc_qmfb1d_getnumchans(qmfb) == 2);      */
1616
 
        assert(start <= end);
1617
 
        bands[0].start = JPC_CEILDIVPOW2(start, 1);
1618
 
        bands[0].end = JPC_CEILDIVPOW2(end, 1);
1619
 
        bands[0].locstart = start;
1620
 
        bands[0].locend = start + bands[0].end - bands[0].start;
1621
 
        bands[1].start = JPC_FLOORDIVPOW2(start, 1);
1622
 
        bands[1].end = JPC_FLOORDIVPOW2(end, 1);
1623
 
        bands[1].locstart = bands[0].locend;
1624
 
        bands[1].locend = bands[1].locstart + bands[1].end - bands[1].start;
1625
 
        assert(bands[1].locend == end);
1626
 
        *numbandsptr = 2;
1627
 
}
1628
 
 
1629
 
/******************************************************************************\
1630
 
*
1631
 
\******************************************************************************/
1632
 
 
1633
 
int jpc_qmfb1d_getnumchans(jpc_qmfb1d_t *qmfb)
1634
 
{
1635
 
        return (*qmfb->ops->getnumchans)(qmfb);
1636
 
}
1637
 
 
1638
 
int jpc_qmfb1d_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
1639
 
{
1640
 
        return (*qmfb->ops->getanalfilters)(qmfb, len, filters);
1641
 
}
1642
 
 
1643
 
int jpc_qmfb1d_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
1644
 
{
1645
 
        return (*qmfb->ops->getsynfilters)(qmfb, len, filters);
1646
 
}
1647
 
 
1648
 
void jpc_qmfb1d_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
1649
 
{
1650
 
        (*qmfb->ops->analyze)(qmfb, flags, x);
1651
 
}
1652
 
 
1653
 
void jpc_qmfb1d_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
1654
 
{
1655
 
        (*qmfb->ops->synthesize)(qmfb, flags, x);
1656
 
}
 
1
/*
 
2
 * Copyright (c) 1999-2000 Image Power, Inc. and the University of
 
3
 *   British Columbia.
 
4
 * Copyright (c) 2001-2003 Michael David Adams.
 
5
 * Copyright (c) 2005-2006 Artifex Software, Inc.
 
6
 *
 
7
 * All rights reserved.
 
8
 */
 
9
 
 
10
/* __START_OF_JASPER_LICENSE__
 
11
 * 
 
12
 * JasPer License Version 2.0
 
13
 * 
 
14
 * Copyright (c) 1999-2000 Image Power, Inc.
 
15
 * Copyright (c) 1999-2000 The University of British Columbia
 
16
 * Copyright (c) 2001-2003 Michael David Adams
 
17
 * 
 
18
 * All rights reserved.
 
19
 * 
 
20
 * Permission is hereby granted, free of charge, to any person (the
 
21
 * "User") obtaining a copy of this software and associated documentation
 
22
 * files (the "Software"), to deal in the Software without restriction,
 
23
 * including without limitation the rights to use, copy, modify, merge,
 
24
 * publish, distribute, and/or sell copies of the Software, and to permit
 
25
 * persons to whom the Software is furnished to do so, subject to the
 
26
 * following conditions:
 
27
 * 
 
28
 * 1.  The above copyright notices and this permission notice (which
 
29
 * includes the disclaimer below) shall be included in all copies or
 
30
 * substantial portions of the Software.
 
31
 * 
 
32
 * 2.  The name of a copyright holder shall not be used to endorse or
 
33
 * promote products derived from the Software without specific prior
 
34
 * written permission.
 
35
 * 
 
36
 * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
 
37
 * LICENSE.  NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
 
38
 * THIS DISCLAIMER.  THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
 
39
 * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 
40
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 
41
 * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.  IN NO
 
42
 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
 
43
 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
 
44
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
45
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
46
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.  NO ASSURANCES ARE
 
47
 * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
 
48
 * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
 
49
 * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
 
50
 * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
 
51
 * PROPERTY RIGHTS OR OTHERWISE.  AS A CONDITION TO EXERCISING THE RIGHTS
 
52
 * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
 
53
 * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY.  THE SOFTWARE
 
54
 * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
 
55
 * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
 
56
 * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
 
57
 * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
 
58
 * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
 
59
 * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
 
60
 * RISK ACTIVITIES").  THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
 
61
 * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
 
62
 * 
 
63
 * __END_OF_JASPER_LICENSE__
 
64
 */
 
65
 
 
66
/*
 
67
 * Quadrature Mirror-Image Filter Bank (QMFB) Library
 
68
 *
 
69
 * $Id$
 
70
 */
 
71
 
 
72
/******************************************************************************\
 
73
* Includes.
 
74
\******************************************************************************/
 
75
 
 
76
#include <assert.h>
 
77
 
 
78
#include "jasper/jas_fix.h"
 
79
#include "jasper/jas_malloc.h"
 
80
#include "jasper/jas_math.h"
 
81
#include "jasper/jas_debug.h"
 
82
 
 
83
#include "jpc_qmfb.h"
 
84
#include "jpc_tsfb.h"
 
85
#include "jpc_math.h"
 
86
 
 
87
#ifndef USE_ASM_MSVC
 
88
# if defined(_MSC_VER) && !defined(_WIN64) && !defined(__BORLANDC__)
 
89
#  define USE_ASM_MSVC
 
90
# endif
 
91
#endif
 
92
 
 
93
/******************************************************************************\
 
94
*
 
95
\******************************************************************************/
 
96
 
 
97
static jpc_qmfb1d_t *jpc_qmfb1d_create(void);
 
98
 
 
99
static int jpc_ft_getnumchans(jpc_qmfb1d_t *qmfb);
 
100
static int jpc_ft_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
 
101
static int jpc_ft_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
 
102
static void jpc_ft_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
 
103
static void jpc_ft_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
 
104
 
 
105
static int jpc_ns_getnumchans(jpc_qmfb1d_t *qmfb);
 
106
static int jpc_ns_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
 
107
static int jpc_ns_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters);
 
108
static void jpc_ns_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
 
109
 
 
110
 
 
111
static void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
 
112
 
 
113
#ifdef USE_ASM_MSVC
 
114
static void jpc_msvc_ns_synthesize( jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
 
115
#endif
 
116
 
 
117
/******************************************************************************\
 
118
*
 
119
\******************************************************************************/
 
120
 
 
121
jpc_qmfb1dops_t jpc_ft_ops = {
 
122
        jpc_ft_getnumchans,
 
123
        jpc_ft_getanalfilters,
 
124
        jpc_ft_getsynfilters,
 
125
        jpc_ft_analyze,
 
126
        jpc_ft_synthesize
 
127
};
 
128
 
 
129
jpc_qmfb1dops_t jpc_ns_ops = {
 
130
        jpc_ns_getnumchans,
 
131
        jpc_ns_getanalfilters,
 
132
        jpc_ns_getsynfilters,
 
133
        jpc_ns_analyze,
 
134
#ifdef USE_ASM_MSVC
 
135
        jpc_msvc_ns_synthesize
 
136
#else
 
137
        jpc_ns_synthesize
 
138
#endif
 
139
};
 
140
 
 
141
/******************************************************************************\
 
142
*
 
143
\******************************************************************************/
 
144
 
 
145
static void jpc_qmfb1d_setup(jpc_fix_t *startptr, int startind, int endind,
 
146
  int intrastep, jpc_fix_t **lstartptr, int *lstartind, int *lendind,
 
147
  jpc_fix_t **hstartptr, int *hstartind, int *hendind)
 
148
{
 
149
        *lstartind = JPC_CEILDIVPOW2(startind, 1);
 
150
        *lendind = JPC_CEILDIVPOW2(endind, 1);
 
151
        *hstartind = JPC_FLOORDIVPOW2(startind, 1);
 
152
        *hendind = JPC_FLOORDIVPOW2(endind, 1);
 
153
        *lstartptr = startptr;
 
154
        *hstartptr = &startptr[(*lendind - *lstartind) * intrastep];
 
155
}
 
156
 
 
157
static void jpc_qmfb1d_split(jpc_fix_t *startptr, int startind, int endind,
 
158
  register int step, jpc_fix_t *lstartptr, int lstartind, int lendind,
 
159
  jpc_fix_t *hstartptr, int hstartind, int hendind)
 
160
{
 
161
        int bufsize = JPC_CEILDIVPOW2(endind - startind, 2);
 
162
#if !defined(HAVE_VLA)
 
163
#define QMFB_SPLITBUFSIZE 4096
 
164
        jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE];
 
165
#else
 
166
        jpc_fix_t splitbuf[bufsize];
 
167
#endif
 
168
        jpc_fix_t *buf = splitbuf;
 
169
        int llen;
 
170
        int hlen;
 
171
        int twostep;
 
172
        jpc_fix_t *tmpptr;
 
173
        register jpc_fix_t *ptr;
 
174
        register jpc_fix_t *hptr;
 
175
        register jpc_fix_t *lptr;
 
176
        register int n;
 
177
        int state;
 
178
 
 
179
        twostep = step << 1;
 
180
        llen = lendind - lstartind;
 
181
        hlen = hendind - hstartind;
 
182
 
 
183
#if !defined(HAVE_VLA)
 
184
        /* Get a buffer. */
 
185
        if (bufsize > QMFB_SPLITBUFSIZE) {
 
186
                if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
 
187
                        /* We have no choice but to commit suicide in this case. */
 
188
                        jas_error(      JAS_ERR_MALLOC_FAILURE_JPC_QMFB1D_SPLIT,
 
189
                                                "JAS_ERR_MALLOC_FAILURE_JPC_QMFB1D_SPLIT"
 
190
                                        );
 
191
                        return;
 
192
                }
 
193
        }
 
194
#endif
 
195
 
 
196
        if (hstartind < lstartind) {
 
197
                /* The first sample in the input signal is to appear
 
198
                  in the highpass subband signal. */
 
199
                /* Copy the appropriate samples into the lowpass subband
 
200
                  signal, saving any samples destined for the highpass subband
 
201
                  signal as they are overwritten. */
 
202
                tmpptr = buf;
 
203
                ptr = &startptr[step];
 
204
                lptr = lstartptr;
 
205
                n = llen;
 
206
                state = 1;
 
207
                while (n-- > 0) {
 
208
                        if (state) {
 
209
                                *tmpptr = *lptr;
 
210
                                ++tmpptr;
 
211
                        }
 
212
                        *lptr = *ptr;
 
213
                        ptr += twostep;
 
214
                        lptr += step;
 
215
                        state ^= 1;
 
216
                }
 
217
                /* Copy the appropriate samples into the highpass subband
 
218
                  signal. */
 
219
                /* Handle the nonoverwritten samples. */
 
220
                hptr = &hstartptr[(hlen - 1) * step];
 
221
                ptr = &startptr[(((llen + hlen - 1) >> 1) << 1) * step];
 
222
                n = hlen - (tmpptr - buf);
 
223
                while (n-- > 0) {
 
224
                        *hptr = *ptr;
 
225
                        hptr -= step;
 
226
                        ptr -= twostep;
 
227
                }
 
228
                /* Handle the overwritten samples. */
 
229
                n = tmpptr - buf;
 
230
                while (n-- > 0) {
 
231
                        --tmpptr;
 
232
                        *hptr = *tmpptr;
 
233
                        hptr -= step;
 
234
                }
 
235
        } else {
 
236
                /* The first sample in the input signal is to appear
 
237
                  in the lowpass subband signal. */
 
238
                /* Copy the appropriate samples into the lowpass subband
 
239
                  signal, saving any samples for the highpass subband
 
240
                  signal as they are overwritten. */
 
241
                state = 0;
 
242
                ptr = startptr;
 
243
                lptr = lstartptr;
 
244
                tmpptr = buf;
 
245
                n = llen;
 
246
                while (n-- > 0) {
 
247
                        if (state) {
 
248
                                *tmpptr = *lptr;
 
249
                                ++tmpptr;
 
250
                        }
 
251
                        *lptr = *ptr;
 
252
                        ptr += twostep;
 
253
                        lptr += step;
 
254
                        state ^= 1;
 
255
                }
 
256
                /* Copy the appropriate samples into the highpass subband
 
257
                  signal. */
 
258
                /* Handle the nonoverwritten samples. */
 
259
                ptr = &startptr[((((llen + hlen) >> 1) << 1) - 1) * step];
 
260
                hptr = &hstartptr[(hlen - 1) * step];
 
261
                n = hlen - (tmpptr - buf);
 
262
                while (n-- > 0) {
 
263
                        *hptr = *ptr;
 
264
                        ptr -= twostep;
 
265
                        hptr -= step;
 
266
                }
 
267
                /* Handle the overwritten samples. */
 
268
                n = tmpptr - buf;
 
269
                while (n-- > 0) {
 
270
                        --tmpptr;
 
271
                        *hptr = *tmpptr;
 
272
                        hptr -= step;
 
273
                }
 
274
        }
 
275
 
 
276
#if !defined(HAVE_VLA)
 
277
        /* If the split buffer was allocated on the heap, free this memory. */
 
278
        if (buf != splitbuf) {
 
279
                jas_free(buf);
 
280
        }
 
281
#endif
 
282
}
 
283
 
 
284
static void jpc_qmfb1d_join(jpc_fix_t *startptr, int startind, int endind,
 
285
  register int step, jpc_fix_t *lstartptr, int lstartind, int lendind,
 
286
  jpc_fix_t *hstartptr, int hstartind, int hendind)
 
287
{
 
288
        int bufsize = JPC_CEILDIVPOW2(endind - startind, 2);
 
289
#if !defined(HAVE_VLA)
 
290
#define QMFB_JOINBUFSIZE        4096
 
291
        jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
 
292
#else
 
293
        jpc_fix_t joinbuf[bufsize];
 
294
#endif
 
295
        jpc_fix_t *buf = joinbuf;
 
296
        int llen;
 
297
        int hlen;
 
298
        int twostep;
 
299
        jpc_fix_t *tmpptr;
 
300
        register jpc_fix_t *ptr;
 
301
        register jpc_fix_t *hptr;
 
302
        register jpc_fix_t *lptr;
 
303
        register int n;
 
304
        int state;
 
305
 
 
306
#if !defined(HAVE_VLA)
 
307
        /* Allocate memory for the join buffer from the heap. */
 
308
        if (bufsize > QMFB_JOINBUFSIZE) {
 
309
                if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
 
310
                        /* We have no choice but to commit suicide. */
 
311
                        jas_error(      JAS_ERR_MALLOC_FAILURE_JPC_QMFB1D_JOIN,
 
312
                                                "JAS_ERR_MALLOC_FAILURE_JPC_QMFB1D_JOIN"
 
313
                                        );
 
314
                        return;
 
315
                }
 
316
        }
 
317
#endif
 
318
 
 
319
        twostep = step << 1;
 
320
        llen = lendind - lstartind;
 
321
        hlen = hendind - hstartind;
 
322
 
 
323
        if (hstartind < lstartind) {
 
324
                /* The first sample in the highpass subband signal is to
 
325
                  appear first in the output signal. */
 
326
                /* Copy the appropriate samples into the first phase of the
 
327
                  output signal. */
 
328
                tmpptr = buf;
 
329
                hptr = hstartptr;
 
330
                ptr = startptr;
 
331
                n = (llen + 1) >> 1;
 
332
                while (n-- > 0) {
 
333
                        *tmpptr = *ptr;
 
334
                        *ptr = *hptr;
 
335
                        ++tmpptr;
 
336
                        ptr += twostep;
 
337
                        hptr += step;
 
338
                }
 
339
                n = hlen - ((llen + 1) >> 1);
 
340
                while (n-- > 0) {
 
341
                        *ptr = *hptr;
 
342
                        ptr += twostep;
 
343
                        hptr += step;
 
344
                }
 
345
                /* Copy the appropriate samples into the second phase of
 
346
                  the output signal. */
 
347
                ptr -= (lendind > hendind) ? (step) : (step + twostep);
 
348
                state = !((llen - 1) & 1);
 
349
                lptr = &lstartptr[(llen - 1) * step];
 
350
                n = llen;
 
351
                while (n-- > 0) {
 
352
                        if (state) {
 
353
                                --tmpptr;
 
354
                                *ptr = *tmpptr;
 
355
                        } else {
 
356
                                *ptr = *lptr;
 
357
                        }
 
358
                        lptr -= step;
 
359
                        ptr -= twostep;
 
360
                        state ^= 1;
 
361
                }
 
362
        } else {
 
363
                /* The first sample in the lowpass subband signal is to
 
364
                  appear first in the output signal. */
 
365
                /* Copy the appropriate samples into the first phase of the
 
366
                  output signal (corresponding to even indexed samples). */
 
367
                lptr = &lstartptr[(llen - 1) * step];
 
368
                ptr = &startptr[((llen - 1) << 1) * step];
 
369
                n = llen >> 1;
 
370
                tmpptr = buf;
 
371
                while (n-- > 0) {
 
372
                        *tmpptr = *ptr;
 
373
                        *ptr = *lptr;
 
374
                        ++tmpptr;
 
375
                        ptr -= twostep;
 
376
                        lptr -= step;
 
377
                }
 
378
                n = llen - (llen >> 1);
 
379
                while (n-- > 0) {
 
380
                        *ptr = *lptr;
 
381
                        ptr -= twostep;
 
382
                        lptr -= step;
 
383
                }
 
384
                /* Copy the appropriate samples into the second phase of
 
385
                  the output signal (corresponding to odd indexed
 
386
                  samples). */
 
387
                ptr = &startptr[step];
 
388
                hptr = hstartptr;
 
389
                state = !(llen & 1);
 
390
                n = hlen;
 
391
                while (n-- > 0) {
 
392
                        if (state) {
 
393
                                --tmpptr;
 
394
                                *ptr = *tmpptr;
 
395
                        } else {
 
396
                                *ptr = *hptr;
 
397
                        }
 
398
                        hptr += step;
 
399
                        ptr += twostep;
 
400
                        state ^= 1;
 
401
                }
 
402
        }
 
403
 
 
404
#if !defined(HAVE_VLA)
 
405
        /* If the join buffer was allocated on the heap, free this memory. */
 
406
        if (buf != joinbuf) {
 
407
                jas_free(buf);
 
408
        }
 
409
#endif
 
410
}
 
411
 
 
412
/******************************************************************************\
 
413
* Code for 5/3 transform.
 
414
\******************************************************************************/
 
415
 
 
416
static int jpc_ft_getnumchans(jpc_qmfb1d_t *qmfb)
 
417
{
 
418
        /* Avoid compiler warnings about unused parameters. */
 
419
        qmfb = 0;
 
420
 
 
421
        return 2;
 
422
}
 
423
 
 
424
static int jpc_ft_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
 
425
{
 
426
        /* Avoid compiler warnings about unused parameters. */
 
427
        qmfb = 0;
 
428
        len = 0;
 
429
        filters = 0;
 
430
 
 
431
        jas_error(      JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_FT_GETANALFILTERS,
 
432
                                "JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_FT_GETANALFILTERS"
 
433
                        );
 
434
        return -1;
 
435
}
 
436
 
 
437
static int jpc_ft_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
 
438
{
 
439
        jas_seq_t *lf;
 
440
        jas_seq_t *hf;
 
441
 
 
442
        /* Avoid compiler warnings about unused parameters. */
 
443
        qmfb = 0;
 
444
 
 
445
        lf = 0;
 
446
        hf = 0;
 
447
 
 
448
        if (len > 1 || (!len)) {
 
449
                if (!(lf = jas_seq_create(-1, 2))) {
 
450
                        goto error;
 
451
                }
 
452
                jas_seq_set(lf, -1, jpc_dbltofix(0.5));
 
453
                jas_seq_set(lf, 0, jpc_dbltofix(1.0));
 
454
                jas_seq_set(lf, 1, jpc_dbltofix(0.5));
 
455
                if (!(hf = jas_seq_create(-1, 4))) {
 
456
                        goto error;
 
457
                }
 
458
                jas_seq_set(hf, -1, jpc_dbltofix(-0.125));
 
459
                jas_seq_set(hf, 0, jpc_dbltofix(-0.25));
 
460
                jas_seq_set(hf, 1, jpc_dbltofix(0.75));
 
461
                jas_seq_set(hf, 2, jpc_dbltofix(-0.25));
 
462
                jas_seq_set(hf, 3, jpc_dbltofix(-0.125));
 
463
        } else if (len == 1) {
 
464
                if (!(lf = jas_seq_create(0, 1))) {
 
465
                        goto error;
 
466
                }
 
467
                jas_seq_set(lf, 0, jpc_dbltofix(1.0));
 
468
                if (!(hf = jas_seq_create(0, 1))) {
 
469
                        goto error;
 
470
                }
 
471
                jas_seq_set(hf, 0, jpc_dbltofix(2.0));
 
472
        } else {
 
473
                jas_error(      JAS_ERR_INVALID_LEN_PARAM_JPC_FT_GETSYNFILTERS,
 
474
                                        "JAS_ERR_INVALID_LEN_PARAM_JPC_FT_GETSYNFILTERS"
 
475
                                );
 
476
                goto error;
 
477
        }
 
478
 
 
479
        filters[0] = lf;
 
480
        filters[1] = hf;
 
481
 
 
482
        return 0;
 
483
 
 
484
error:
 
485
        if (lf) {
 
486
                jas_seq_destroy(lf);
 
487
        }
 
488
        if (hf) {
 
489
                jas_seq_destroy(hf);
 
490
        }
 
491
        return -1;
 
492
}
 
493
 
 
494
#define NFT_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pluseq) \
 
495
{ \
 
496
        register jpc_fix_t *lptr = (lstartptr); \
 
497
        register jpc_fix_t *hptr = (hstartptr); \
 
498
        register int n = (hendind) - (hstartind); \
 
499
        if ((hstartind) < (lstartind)) { \
 
500
                pluseq(*hptr, *lptr); \
 
501
                hptr += (step); \
 
502
                --n; \
 
503
        } \
 
504
        if ((hendind) >= (lendind)) { \
 
505
                --n; \
 
506
        } \
 
507
        while (n-- > 0) { \
 
508
                pluseq(*hptr, jpc_fix_asr(jpc_fix_add(*lptr, lptr[(step)]), 1)); \
 
509
                hptr += (step); \
 
510
                lptr += (step); \
 
511
        } \
 
512
        if ((hendind) >= (lendind)) { \
 
513
                pluseq(*hptr, *lptr); \
 
514
        } \
 
515
}
 
516
 
 
517
#define NFT_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pluseq) \
 
518
{ \
 
519
        register jpc_fix_t *lptr = (lstartptr); \
 
520
        register jpc_fix_t *hptr = (hstartptr); \
 
521
        register int n = (lendind) - (lstartind); \
 
522
        if ((hstartind) >= (lstartind)) { \
 
523
                pluseq(*lptr, *hptr); \
 
524
                lptr += (step); \
 
525
                --n; \
 
526
        } \
 
527
        if ((lendind) > (hendind)) { \
 
528
                --n; \
 
529
        } \
 
530
        while (n-- > 0) { \
 
531
                pluseq(*lptr, jpc_fix_asr(jpc_fix_add(*hptr, hptr[(step)]), 2)); \
 
532
                lptr += (step); \
 
533
                hptr += (step); \
 
534
        } \
 
535
        if ((lendind) > (hendind)) { \
 
536
                pluseq(*lptr, *hptr); \
 
537
        } \
 
538
}
 
539
 
 
540
#define RFT_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pmeqop) \
 
541
{ \
 
542
        register jpc_fix_t *lptr = (lstartptr); \
 
543
        register jpc_fix_t *hptr = (hstartptr); \
 
544
        register int n = (hendind) - (hstartind); \
 
545
        if ((hstartind) < (lstartind)) { \
 
546
                *hptr pmeqop *lptr; \
 
547
                hptr += (step); \
 
548
                --n; \
 
549
        } \
 
550
        if ((hendind) >= (lendind)) { \
 
551
                --n; \
 
552
        } \
 
553
        while (n-- > 0) { \
 
554
                *hptr pmeqop (*lptr + lptr[(step)]) >> 1; \
 
555
                hptr += (step); \
 
556
                lptr += (step); \
 
557
        } \
 
558
        if ((hendind) >= (lendind)) { \
 
559
                *hptr pmeqop *lptr; \
 
560
        } \
 
561
}
 
562
 
 
563
#define RFT_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pmeqop) \
 
564
{ \
 
565
        register jpc_fix_t *lptr = (lstartptr); \
 
566
        register jpc_fix_t *hptr = (hstartptr); \
 
567
        register int n = (lendind) - (lstartind); \
 
568
        if ((hstartind) >= (lstartind)) { \
 
569
                *lptr pmeqop ((*hptr << 1) + 2) >> 2; \
 
570
                lptr += (step); \
 
571
                --n; \
 
572
        } \
 
573
        if ((lendind) > (hendind)) { \
 
574
                --n; \
 
575
        } \
 
576
        while (n-- > 0) { \
 
577
                *lptr pmeqop ((*hptr + hptr[(step)]) + 2) >> 2; \
 
578
                lptr += (step); \
 
579
                hptr += (step); \
 
580
        } \
 
581
        if ((lendind) > (hendind)) { \
 
582
                *lptr pmeqop ((*hptr << 1) + 2) >> 2; \
 
583
        } \
 
584
}
 
585
 
 
586
static void jpc_ft_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
 
587
{
 
588
        jpc_fix_t *startptr;
 
589
        int startind;
 
590
        int endind;
 
591
        jpc_fix_t *  lstartptr;
 
592
        int   lstartind;
 
593
        int   lendind;
 
594
        jpc_fix_t *  hstartptr;
 
595
        int   hstartind;
 
596
        int   hendind;
 
597
        int interstep;
 
598
        int intrastep;
 
599
        int numseq;
 
600
 
 
601
        /* Avoid compiler warnings about unused parameters. */
 
602
        qmfb = 0;
 
603
 
 
604
        if (flags & JPC_QMFB1D_VERT) {
 
605
                interstep = 1;
 
606
                intrastep = jas_seq2d_rowstep(x);
 
607
                numseq = jas_seq2d_width(x);
 
608
                startind = jas_seq2d_ystart(x);
 
609
                endind = jas_seq2d_yend(x);
 
610
        } else {
 
611
                interstep = jas_seq2d_rowstep(x);
 
612
                intrastep = 1;
 
613
                numseq = jas_seq2d_height(x);
 
614
                startind = jas_seq2d_xstart(x);
 
615
                endind = jas_seq2d_xend(x);
 
616
        }
 
617
 
 
618
        assert(startind < endind);
 
619
 
 
620
        startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
 
621
        if (flags & JPC_QMFB1D_RITIMODE) {
 
622
                while (numseq-- > 0) {
 
623
                        jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
 
624
                          &lstartptr, &lstartind, &lendind, &hstartptr,
 
625
                          &hstartind, &hendind);
 
626
                        if (endind - startind > 1) {
 
627
                                jpc_qmfb1d_split(startptr, startind, endind,
 
628
                                  intrastep, lstartptr, lstartind, lendind,
 
629
                                  hstartptr, hstartind, hendind);
 
630
                                RFT_LIFT0(lstartptr, lstartind, lendind,
 
631
                                  hstartptr, hstartind, hendind, intrastep, -=);
 
632
                                RFT_LIFT1(lstartptr, lstartind, lendind,
 
633
                                  hstartptr, hstartind, hendind, intrastep, +=);
 
634
                        } else {
 
635
                                if (lstartind == lendind) {
 
636
                                        *startptr <<= 1;
 
637
                                }
 
638
                        }
 
639
                        startptr += interstep;
 
640
                }
 
641
        } else {
 
642
                while (numseq-- > 0) {
 
643
                        jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
 
644
                          &lstartptr, &lstartind, &lendind, &hstartptr,
 
645
                          &hstartind, &hendind);
 
646
                        if (endind - startind > 1) {
 
647
                                jpc_qmfb1d_split(startptr, startind, endind,
 
648
                                  intrastep, lstartptr, lstartind, lendind,
 
649
                                  hstartptr, hstartind, hendind);
 
650
                                NFT_LIFT0(lstartptr, lstartind, lendind,
 
651
                                  hstartptr, hstartind, hendind, intrastep,
 
652
                                  jpc_fix_minuseq);
 
653
                                NFT_LIFT1(lstartptr, lstartind, lendind,
 
654
                                  hstartptr, hstartind, hendind, intrastep,
 
655
                                  jpc_fix_pluseq);
 
656
                        } else {
 
657
                                if (lstartind == lendind) {
 
658
                                        *startptr = jpc_fix_asl(*startptr, 1);
 
659
                                }
 
660
                        }
 
661
                        startptr += interstep;
 
662
                }
 
663
        }
 
664
}
 
665
 
 
666
static void jpc_ft_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
 
667
{
 
668
        jpc_fix_t *startptr;
 
669
        int startind;
 
670
        int endind;
 
671
        jpc_fix_t *lstartptr;
 
672
        int lstartind;
 
673
        int lendind;
 
674
        jpc_fix_t *hstartptr;
 
675
        int hstartind;
 
676
        int hendind;
 
677
        int interstep;
 
678
        int intrastep;
 
679
        int numseq;
 
680
 
 
681
        /* Avoid compiler warnings about unused parameters. */
 
682
        qmfb = 0;
 
683
 
 
684
        if (flags & JPC_QMFB1D_VERT) {
 
685
                interstep = 1;
 
686
                intrastep = jas_seq2d_rowstep(x);
 
687
                numseq = jas_seq2d_width(x);
 
688
                startind = jas_seq2d_ystart(x);
 
689
                endind = jas_seq2d_yend(x);
 
690
        } else {
 
691
                interstep = jas_seq2d_rowstep(x);
 
692
                intrastep = 1;
 
693
                numseq = jas_seq2d_height(x);
 
694
                startind = jas_seq2d_xstart(x);
 
695
                endind = jas_seq2d_xend(x);
 
696
        }
 
697
 
 
698
        assert(startind < endind);
 
699
 
 
700
        startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
 
701
        if (flags & JPC_QMFB1D_RITIMODE) {
 
702
                while (numseq-- > 0) {
 
703
                        jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
 
704
                          &lstartptr, &lstartind, &lendind, &hstartptr,
 
705
                          &hstartind, &hendind);
 
706
                        if (endind - startind > 1) {
 
707
                                RFT_LIFT1(lstartptr, lstartind, lendind,
 
708
                                  hstartptr, hstartind, hendind, intrastep, -=);
 
709
                                RFT_LIFT0(lstartptr, lstartind, lendind,
 
710
                                  hstartptr, hstartind, hendind, intrastep, +=);
 
711
                                jpc_qmfb1d_join(startptr, startind, endind,
 
712
                                  intrastep, lstartptr, lstartind, lendind,
 
713
                                  hstartptr, hstartind, hendind);
 
714
                        } else {
 
715
                                if (lstartind == lendind) {
 
716
                                        *startptr >>= 1;
 
717
                                }
 
718
                        }
 
719
                        startptr += interstep;
 
720
                }
 
721
        } else {
 
722
                while (numseq-- > 0) {
 
723
                        jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
 
724
                          &lstartptr, &lstartind, &lendind, &hstartptr,
 
725
                          &hstartind, &hendind);
 
726
                        if (endind - startind > 1) {
 
727
                                NFT_LIFT1(lstartptr, lstartind, lendind,
 
728
                                  hstartptr, hstartind, hendind, intrastep,
 
729
                                  jpc_fix_minuseq);
 
730
                                NFT_LIFT0(lstartptr, lstartind, lendind,
 
731
                                  hstartptr, hstartind, hendind, intrastep,
 
732
                                  jpc_fix_pluseq);
 
733
                                jpc_qmfb1d_join(startptr, startind, endind,
 
734
                                  intrastep, lstartptr, lstartind, lendind,
 
735
                                  hstartptr, hstartind, hendind);
 
736
                        } else {
 
737
                                if (lstartind == lendind) {
 
738
                                        *startptr = jpc_fix_asr(*startptr, 1);
 
739
                                }
 
740
                        }
 
741
                        startptr += interstep;
 
742
                }
 
743
        }
 
744
}
 
745
 
 
746
/******************************************************************************\
 
747
* Code for 9/7 transform.
 
748
\******************************************************************************/
 
749
 
 
750
static int jpc_ns_getnumchans(jpc_qmfb1d_t *qmfb)
 
751
{
 
752
        /* Avoid compiler warnings about unused parameters. */
 
753
        qmfb = 0;
 
754
 
 
755
        return 2;
 
756
}
 
757
 
 
758
static int jpc_ns_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
 
759
{
 
760
        /* Avoid compiler warnings about unused parameters. */
 
761
        qmfb = 0;
 
762
        len = 0;
 
763
        filters = 0;
 
764
 
 
765
        jas_error(      JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_NS_GETANALFILTERS,
 
766
                                "JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_NS_GETANALFILTERS"
 
767
                        );
 
768
        return -1;
 
769
}
 
770
 
 
771
static int jpc_ns_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
 
772
{
 
773
        jas_seq_t *lf;
 
774
        jas_seq_t *hf;
 
775
 
 
776
        /* Avoid compiler warnings about unused parameters. */
 
777
        qmfb = 0;
 
778
 
 
779
        lf = 0;
 
780
        hf = 0;
 
781
 
 
782
        if (len > 1 || (!len)) {
 
783
                if (!(lf = jas_seq_create(-3, 4))) {
 
784
                        goto error;
 
785
                }
 
786
                jas_seq_set(lf, -3, jpc_dbltofix(-0.09127176311424948));
 
787
                jas_seq_set(lf, -2, jpc_dbltofix(-0.05754352622849957));
 
788
                jas_seq_set(lf, -1, jpc_dbltofix(0.5912717631142470));
 
789
                jas_seq_set(lf, 0, jpc_dbltofix(1.115087052456994));
 
790
                jas_seq_set(lf, 1, jpc_dbltofix(0.5912717631142470));
 
791
                jas_seq_set(lf, 2, jpc_dbltofix(-0.05754352622849957));
 
792
                jas_seq_set(lf, 3, jpc_dbltofix(-0.09127176311424948));
 
793
                if (!(hf = jas_seq_create(-3, 6))) {
 
794
                        goto error;
 
795
                }
 
796
                jas_seq_set(hf, -3, jpc_dbltofix(-0.02674875741080976 * 2.0));
 
797
                jas_seq_set(hf, -2, jpc_dbltofix(-0.01686411844287495 * 2.0));
 
798
                jas_seq_set(hf, -1, jpc_dbltofix(0.07822326652898785 * 2.0));
 
799
                jas_seq_set(hf, 0, jpc_dbltofix(0.2668641184428723 * 2.0));
 
800
                jas_seq_set(hf, 1, jpc_dbltofix(-0.6029490182363579 * 2.0));
 
801
                jas_seq_set(hf, 2, jpc_dbltofix(0.2668641184428723 * 2.0));
 
802
                jas_seq_set(hf, 3, jpc_dbltofix(0.07822326652898785 * 2.0));
 
803
                jas_seq_set(hf, 4, jpc_dbltofix(-0.01686411844287495 * 2.0));
 
804
                jas_seq_set(hf, 5, jpc_dbltofix(-0.02674875741080976 * 2.0));
 
805
        } else if (len == 1) {
 
806
                if (!(lf = jas_seq_create(0, 1))) {
 
807
                        goto error;
 
808
                }
 
809
                jas_seq_set(lf, 0, jpc_dbltofix(1.0));
 
810
                if (!(hf = jas_seq_create(0, 1))) {
 
811
                        goto error;
 
812
                }
 
813
                jas_seq_set(hf, 0, jpc_dbltofix(2.0));
 
814
        } else {
 
815
                jas_error(      JAS_ERR_INVALID_LEN_PARAM_JPC_NS_GETSYNFILTERS,
 
816
                                        "JAS_ERR_INVALID_LEN_PARAM_JPC_NS_GETSYNFILTERS"
 
817
                                );
 
818
                goto error;
 
819
        }
 
820
 
 
821
        filters[0] = lf;
 
822
        filters[1] = hf;
 
823
 
 
824
        return 0;
 
825
 
 
826
error:
 
827
        if (lf) {
 
828
                jas_seq_destroy(lf);
 
829
        }
 
830
        if (hf) {
 
831
                jas_seq_destroy(hf);
 
832
        }
 
833
        return -1;
 
834
}
 
835
 
 
836
#define NNS_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \
 
837
{ \
 
838
        register jpc_fix_t *lptr = (lstartptr); \
 
839
        register jpc_fix_t *hptr = (hstartptr); \
 
840
        register int n = (hendind) - (hstartind); \
 
841
        jpc_fix_t twoalpha = jpc_fix_mulbyint(alpha, 2); \
 
842
        if ((hstartind) < (lstartind)) { \
 
843
                jpc_fix_pluseq(*hptr, jpc_fix_mul(*lptr, (twoalpha))); \
 
844
                hptr += (step); \
 
845
                --n; \
 
846
        } \
 
847
        if ((hendind) >= (lendind)) { \
 
848
                --n; \
 
849
        } \
 
850
        while (n-- > 0) { \
 
851
                jpc_fix_pluseq(*hptr, jpc_fix_mul(jpc_fix_add(*lptr, lptr[(step)]), (alpha))); \
 
852
                hptr += (step); \
 
853
                lptr += (step); \
 
854
        } \
 
855
        if ((hendind) >= (lendind)) { \
 
856
                jpc_fix_pluseq(*hptr, jpc_fix_mul(*lptr, (twoalpha))); \
 
857
        } \
 
858
}
 
859
 
 
860
#define NNS_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \
 
861
{ \
 
862
        register jpc_fix_t *lptr = (lstartptr); \
 
863
        register jpc_fix_t *hptr = (hstartptr); \
 
864
        register int n = (lendind) - (lstartind); \
 
865
        int twoalpha = jpc_fix_mulbyint(alpha, 2); \
 
866
        if ((hstartind) >= (lstartind)) { \
 
867
                jpc_fix_pluseq(*lptr, jpc_fix_mul(*hptr, (twoalpha))); \
 
868
                lptr += (step); \
 
869
                --n; \
 
870
        } \
 
871
        if ((lendind) > (hendind)) { \
 
872
                --n; \
 
873
        } \
 
874
        while (n-- > 0) { \
 
875
                jpc_fix_pluseq(*lptr, jpc_fix_mul(jpc_fix_add(*hptr, hptr[(step)]), (alpha))); \
 
876
                lptr += (step); \
 
877
                hptr += (step); \
 
878
        } \
 
879
        if ((lendind) > (hendind)) { \
 
880
                jpc_fix_pluseq(*lptr, jpc_fix_mul(*hptr, (twoalpha))); \
 
881
        } \
 
882
}
 
883
 
 
884
#define NNS_SCALE(startptr, startind, endind, step, alpha) \
 
885
{ \
 
886
        register jpc_fix_t *ptr = (startptr); \
 
887
        register int n = (endind) - (startind); \
 
888
        while (n-- > 0) { \
 
889
                jpc_fix_muleq(*ptr, alpha); \
 
890
                ptr += (step); \
 
891
        } \
 
892
}
 
893
 
 
894
static void jpc_ns_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
 
895
{
 
896
        jpc_fix_t *startptr;
 
897
        int startind;
 
898
        int endind;
 
899
        jpc_fix_t *lstartptr;
 
900
        int lstartind;
 
901
        int lendind;
 
902
        jpc_fix_t *hstartptr;
 
903
        int hstartind;
 
904
        int hendind;
 
905
        int interstep;
 
906
        int intrastep;
 
907
        int numseq;
 
908
 
 
909
        /* Avoid compiler warnings about unused parameters. */
 
910
        qmfb = 0;
 
911
 
 
912
        if (flags & JPC_QMFB1D_VERT) {
 
913
                interstep = 1;
 
914
                intrastep = jas_seq2d_rowstep(x);
 
915
                numseq = jas_seq2d_width(x);
 
916
                startind = jas_seq2d_ystart(x);
 
917
                endind = jas_seq2d_yend(x);
 
918
        } else {
 
919
                interstep = jas_seq2d_rowstep(x);
 
920
                intrastep = 1;
 
921
                numseq = jas_seq2d_height(x);
 
922
                startind = jas_seq2d_xstart(x);
 
923
                endind = jas_seq2d_xend(x);
 
924
        }
 
925
 
 
926
        assert(startind < endind);
 
927
 
 
928
        startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
 
929
        if (!(flags & JPC_QMFB1D_RITIMODE)) {
 
930
                while (numseq-- > 0) {
 
931
                        jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
 
932
                          &lstartptr, &lstartind, &lendind, &hstartptr,
 
933
                          &hstartind, &hendind);
 
934
                        if (endind - startind > 1) {
 
935
                                jpc_qmfb1d_split(startptr, startind, endind,
 
936
                                  intrastep, lstartptr, lstartind, lendind,
 
937
                                  hstartptr, hstartind, hendind);
 
938
                                NNS_LIFT0(lstartptr, lstartind, lendind,
 
939
                                  hstartptr, hstartind, hendind, intrastep,
 
940
                                  jpc_dbltofix(-1.586134342));
 
941
                                NNS_LIFT1(lstartptr, lstartind, lendind,
 
942
                                  hstartptr, hstartind, hendind, intrastep,
 
943
                                  jpc_dbltofix(-0.052980118));
 
944
                                NNS_LIFT0(lstartptr, lstartind, lendind,
 
945
                                  hstartptr, hstartind, hendind, intrastep,
 
946
                                  jpc_dbltofix(0.882911075));
 
947
                                NNS_LIFT1(lstartptr, lstartind, lendind,
 
948
                                  hstartptr, hstartind, hendind, intrastep,
 
949
                                  jpc_dbltofix(0.443506852));
 
950
                                NNS_SCALE(lstartptr, lstartind, lendind,
 
951
                                  intrastep, jpc_dbltofix(1.0/1.23017410558578));
 
952
                                NNS_SCALE(hstartptr, hstartind, hendind,
 
953
                                  intrastep, jpc_dbltofix(1.0/1.62578613134411));
 
954
                        } else {
 
955
#if 0
 
956
                                if (lstartind == lendind) {
 
957
                                        *startptr = jpc_fix_asl(*startptr, 1);
 
958
                                }
 
959
#endif
 
960
                        }
 
961
                        startptr += interstep;
 
962
                }
 
963
        } else {
 
964
                /* The reversible integer-to-integer mode is not supported
 
965
                  for this transform. */
 
966
                jas_error(      JAS_ERR_UNSUPPORTED_MODE_JPC_NS_ANALYZE,
 
967
                                        "JAS_ERR_UNSUPPORTED_MODE_JPC_NS_ANALYZE"
 
968
                                );
 
969
        }
 
970
}
 
971
 
 
972
 
 
973
#ifdef USE_ASM_MSVC
 
974
 
 
975
#define DBL_FIX_A       (0x0000275d)
 
976
#define DBL_FIX_B       (0x00003406)
 
977
#define DBL_FIX_C       (0xfffff1cf)
 
978
#define DBL_FIX_D       (0xffffe3c0)
 
979
#define DBL_FIX_E       (0x000001b2)
 
980
#define DBL_FIX_F       (0x000032c1)
 
981
 
 
982
#define twoalpha_C      (0xffffe39e)
 
983
#define twoalpha_D      (0xffffc780)
 
984
#define twoalpha_E      (0x00000364)
 
985
#define twoalpha_F      (0x00006582)
 
986
 
 
987
#endif
 
988
 
 
989
 
 
990
 
 
991
 
 
992
void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
 
993
{
 
994
        jpc_fix_t *startptr;
 
995
        int startind;
 
996
        int endind;
 
997
        jpc_fix_t *lstartptr;
 
998
        int lstartind;
 
999
        int lendind;
 
1000
        jpc_fix_t *hstartptr;
 
1001
        int hstartind;
 
1002
        int hendind;
 
1003
        int interstep;
 
1004
        int intrastep;
 
1005
        int numseq;
 
1006
 
 
1007
        /* Avoid compiler warnings about unused parameters. */
 
1008
        qmfb = 0;
 
1009
 
 
1010
        if (flags & JPC_QMFB1D_VERT) {
 
1011
                interstep = 1;
 
1012
                intrastep = jas_seq2d_rowstep(x);
 
1013
                numseq = jas_seq2d_width(x);
 
1014
                startind = jas_seq2d_ystart(x);
 
1015
                endind = jas_seq2d_yend(x);
 
1016
        } else {
 
1017
                interstep = jas_seq2d_rowstep(x);
 
1018
                intrastep = 1;
 
1019
                numseq = jas_seq2d_height(x);
 
1020
                startind = jas_seq2d_xstart(x);
 
1021
                endind = jas_seq2d_xend(x);
 
1022
        }
 
1023
 
 
1024
        assert(startind < endind);
 
1025
 
 
1026
        startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
 
1027
        if (!(flags & JPC_QMFB1D_RITIMODE)) {
 
1028
                while (numseq-- > 0) {
 
1029
                        jpc_qmfb1d_setup(startptr, startind, endind, intrastep,
 
1030
                          &lstartptr, &lstartind, &lendind, &hstartptr,
 
1031
                          &hstartind, &hendind);
 
1032
                        if (endind - startind > 1) {
 
1033
                                NNS_SCALE(lstartptr, lstartind, lendind,
 
1034
                                  intrastep, jpc_dbltofix(1.23017410558578));
 
1035
                                NNS_SCALE(hstartptr, hstartind, hendind,
 
1036
                                  intrastep, jpc_dbltofix(1.62578613134411));
 
1037
                                NNS_LIFT1(lstartptr, lstartind, lendind,
 
1038
                                  hstartptr, hstartind, hendind, intrastep,
 
1039
                                  jpc_dbltofix(-0.443506852));
 
1040
                                NNS_LIFT0(lstartptr, lstartind, lendind,
 
1041
                                  hstartptr, hstartind, hendind, intrastep,
 
1042
                                  jpc_dbltofix(-0.882911075));
 
1043
                                NNS_LIFT1(lstartptr, lstartind, lendind,
 
1044
                                  hstartptr, hstartind, hendind, intrastep,
 
1045
                                  jpc_dbltofix(0.052980118));
 
1046
                                NNS_LIFT0(lstartptr, lstartind, lendind,
 
1047
                                  hstartptr, hstartind, hendind, intrastep,
 
1048
                                  jpc_dbltofix(1.586134342));
 
1049
                                jpc_qmfb1d_join(startptr, startind, endind,
 
1050
                                  intrastep, lstartptr, lstartind, lendind,
 
1051
                                  hstartptr, hstartind, hendind);
 
1052
                        } else {
 
1053
#if 0
 
1054
                                if (lstartind == lendind) {
 
1055
                                        *startptr = jpc_fix_asr(*startptr, 1);
 
1056
                                }
 
1057
#endif
 
1058
                        }
 
1059
                        startptr += interstep;
 
1060
                }
 
1061
        } else {
 
1062
                /* The reversible integer-to-integer mode is not supported
 
1063
                  for this transform. */
 
1064
                jas_error(      JAS_ERR_UNSUPPORTED_MODE_JPC_NS_SYNTHESIZE,
 
1065
                                        "JAS_ERR_UNSUPPORTED_MODE_JPC_NS_SYNTHESIZE"
 
1066
                                );
 
1067
        }
 
1068
}
 
1069
 
 
1070
 
 
1071
 
 
1072
#ifdef USE_ASM_MSVC
 
1073
 
 
1074
 
 
1075
#define USE_LF_ASM
 
1076
 
 
1077
void jpc_msvc_ns_synthesize(   jpc_qmfb1d_t *qmfb, 
 
1078
                                                                int flags, 
 
1079
                                                                jas_seq2d_t *x
 
1080
                                                        )
 
1081
{
 
1082
        jpc_fix_t *startptr;
 
1083
        int startind;
 
1084
        int endind;
 
1085
        jpc_fix_t *lstartptr;
 
1086
        int lstartind;
 
1087
        int lendind;
 
1088
        jpc_fix_t *hstartptr;
 
1089
        int hstartind;
 
1090
        int hendind;
 
1091
        int interstep;
 
1092
        int intrastep;
 
1093
        int numseq;
 
1094
 
 
1095
        /* Avoid compiler warnings about unused parameters. */
 
1096
        qmfb = 0;
 
1097
 
 
1098
        if (flags & JPC_QMFB1D_VERT) 
 
1099
        {
 
1100
                interstep = 1;
 
1101
                intrastep = jas_seq2d_rowstep(x);
 
1102
                numseq = jas_seq2d_width(x);
 
1103
                startind = jas_seq2d_ystart(x);
 
1104
                endind = jas_seq2d_yend(x);
 
1105
        } 
 
1106
        else 
 
1107
        {
 
1108
                interstep = jas_seq2d_rowstep(x);
 
1109
                intrastep = 1;
 
1110
                numseq = jas_seq2d_height(x);
 
1111
                startind = jas_seq2d_xstart(x);
 
1112
                endind = jas_seq2d_xend(x);
 
1113
        }
 
1114
 
 
1115
        assert(startind < endind);
 
1116
 
 
1117
        startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
 
1118
 
 
1119
        if (!(flags & JPC_QMFB1D_RITIMODE)) 
 
1120
        {
 
1121
                while (numseq-- > 0) 
 
1122
                {
 
1123
                        jpc_qmfb1d_setup(       startptr, 
 
1124
                                                                startind, 
 
1125
                                                                endind, 
 
1126
                                                                intrastep,
 
1127
                                                                &lstartptr, 
 
1128
                                                                &lstartind, 
 
1129
                                                                &lendind, 
 
1130
                                                                &hstartptr,
 
1131
                                                                &hstartind, 
 
1132
                                                                &hendind
 
1133
                                                        );
 
1134
 
 
1135
                        if (endind - startind > 1) 
 
1136
                        {
 
1137
#if !defined(USE_LF_ASM)
 
1138
                                NNS_SCALE(      lstartptr, 
 
1139
                                                        lstartind, 
 
1140
                                                        lendind,
 
1141
                                                        intrastep, 
 
1142
                                                        DBL_FIX_A
 
1143
                                                );
 
1144
#else
 
1145
 
 
1146
        __asm   mov     esi,    lstartptr
 
1147
        __asm   mov     eax,    lstartind
 
1148
        __asm   mov ebx,        lendind
 
1149
        __asm   sub ebx,        eax
 
1150
        __asm   mov                     ecx, intrastep
 
1151
        __asm   shl                     ecx, 2
 
1152
 
 
1153
scale_lp0:      ;
 
1154
        __asm   test    ebx, ebx
 
1155
        __asm   je              skip_scale0
 
1156
 
 
1157
        __asm   mov             eax, [esi]
 
1158
        __asm   test    eax, eax
 
1159
        __asm   je              skip_mul0
 
1160
        __asm   mov             edx, DBL_FIX_A
 
1161
        __asm   imul    edx
 
1162
        __asm   shrd    eax, edx, JPC_FIX_FRACBITS
 
1163
        __asm   mov             [esi], eax
 
1164
skip_mul0:      ;
 
1165
        __asm   add             esi, ecx
 
1166
        __asm   sub             ebx, 1
 
1167
        __asm   jmp             scale_lp0
 
1168
skip_scale0:    ;
 
1169
 
 
1170
#endif
 
1171
 
 
1172
#if !defined(USE_LF_ASM)
 
1173
                                NNS_SCALE(      hstartptr, 
 
1174
                                                        hstartind, 
 
1175
                                                        hendind,
 
1176
                                                        intrastep, 
 
1177
                                                        DBL_FIX_B
 
1178
                                                );
 
1179
#else
 
1180
 
 
1181
        __asm   mov     esi,    hstartptr
 
1182
        __asm   mov     eax,    hstartind
 
1183
        __asm   mov ebx,        hendind
 
1184
        __asm   sub ebx,        eax
 
1185
 
 
1186
scale_lp1:      ;
 
1187
        __asm   test    ebx, ebx
 
1188
        __asm   je              skip_scale1
 
1189
 
 
1190
        __asm   mov             eax, [esi]
 
1191
        __asm   test    eax, eax
 
1192
        __asm   je              skip_mul1
 
1193
        __asm   mov             edx, DBL_FIX_B
 
1194
        __asm   imul    edx
 
1195
        __asm   shrd    eax, edx, JPC_FIX_FRACBITS
 
1196
        __asm   mov             [esi], eax
 
1197
skip_mul1:      ;
 
1198
        __asm   add             esi, ecx
 
1199
        __asm   sub             ebx, 1
 
1200
        __asm   jmp             scale_lp1
 
1201
skip_scale1:    ;
 
1202
 
 
1203
#endif
 
1204
 
 
1205
#if !defined(USE_LF_ASM)
 
1206
                                RA_NNS_LIFT1(   lstartptr, 
 
1207
                                                                lstartind, 
 
1208
                                                                lendind,
 
1209
                                                                hstartptr, 
 
1210
                                                                hstartind, 
 
1211
                                                                hendind, 
 
1212
                                                                intrastep,
 
1213
                                                                DBL_FIX_C,
 
1214
                                                                twoalpha_C
 
1215
                                                        );
 
1216
#else
 
1217
 
 
1218
        __asm   mov     esi,    lstartptr
 
1219
        __asm   mov     edi,    hstartptr
 
1220
        __asm   mov     eax,    lstartind
 
1221
        __asm   mov ebx,        lendind
 
1222
        __asm   sub ebx,        eax
 
1223
 
 
1224
        __asm   mov     eax,    hstartind
 
1225
        __asm   cmp     eax,    lstartind
 
1226
        __asm   jl                      no_1C
 
1227
        
 
1228
        __asm   mov                     eax, [edi]
 
1229
        __asm   test            eax, eax
 
1230
        __asm   je                      skip_slow1C
 
1231
        __asm   mov                     edx, twoalpha_C
 
1232
        __asm   imul            edx
 
1233
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
 
1234
        __asm   add                     dword ptr[esi], eax
 
1235
skip_slow1C:
 
1236
 
 
1237
        __asm   add                     esi, ecx
 
1238
        __asm   sub                     ebx, 1
 
1239
no_1C:
 
1240
        __asm   mov     eax,    lendind
 
1241
        __asm   cmp     eax,    hendind
 
1242
        __asm   jle                     lpC
 
1243
        __asm   sub                     ebx, 1
 
1244
 
 
1245
lpC:
 
1246
        __asm   test    ebx, ebx
 
1247
        __asm   jle             done_lpC
 
1248
lpaC:
 
1249
        __asm   mov             eax, dword ptr[edi]
 
1250
        __asm   sub             ebx, 1
 
1251
        __asm   add             eax, dword ptr[edi + ecx ]
 
1252
        __asm   test    eax, eax
 
1253
        __asm   je              skip_slowC
 
1254
 
 
1255
        __asm   mov             edx, DBL_FIX_C
 
1256
        __asm   imul    edx
 
1257
        __asm   shrd    eax, edx, JPC_FIX_FRACBITS
 
1258
        __asm   add             dword ptr[esi], eax
 
1259
 
 
1260
skip_slowC:
 
1261
        __asm   add             esi, ecx
 
1262
        __asm   add             edi, ecx
 
1263
        __asm   test    ebx, ebx
 
1264
        __asm   jg              lpaC
 
1265
done_lpC:                                       ;
 
1266
 
 
1267
        __asm   mov     eax,    lendind
 
1268
        __asm   cmp     eax,    hendind
 
1269
        __asm   jle                     no_3C
 
1270
        __asm   mov                     eax, dword ptr[edi]
 
1271
        __asm   test            eax, eax
 
1272
        __asm   je                      no_3C
 
1273
        __asm   mov                     edx, dword ptr[twoalpha_C]
 
1274
        __asm   imul            edx
 
1275
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
 
1276
        __asm   add                     dword ptr[esi],eax
 
1277
no_3C:          ;
 
1278
 
 
1279
#endif
 
1280
 
 
1281
 
 
1282
#if !defined(USE_LF_ASM)
 
1283
                                NNS_LIFT0(      lstartptr, 
 
1284
                                                        lstartind, 
 
1285
                                                        lendind,
 
1286
                                                        hstartptr, 
 
1287
                                                        hstartind, 
 
1288
                                                        hendind, 
 
1289
                                                        intrastep,
 
1290
                                                        DBL_FIX_D
 
1291
                                                );
 
1292
#else
 
1293
 
 
1294
        __asm   mov     esi,    lstartptr
 
1295
        __asm   mov     edi,    hstartptr
 
1296
        __asm   mov     eax,    hstartind
 
1297
        __asm   mov ebx,        hendind
 
1298
        __asm   sub ebx,        eax
 
1299
 
 
1300
        __asm   mov     eax,    hstartind
 
1301
        __asm   cmp     eax,    lstartind
 
1302
        __asm   jge                     no_lift0a
 
1303
        
 
1304
        __asm   mov                     eax, [edi]
 
1305
        __asm   test            eax, eax
 
1306
        __asm   je                      skip_slow_lift0
 
1307
        __asm   mov                     edx, twoalpha_D
 
1308
        __asm   imul            edx
 
1309
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
 
1310
        __asm   add                     dword ptr[esi], eax
 
1311
skip_slow_lift0:
 
1312
 
 
1313
        __asm   add                     esi, ecx
 
1314
        __asm   sub                     ebx, 1
 
1315
no_lift0a:
 
1316
 
 
1317
        __asm   mov     eax,    hendind
 
1318
        __asm   cmp     eax,    lendind
 
1319
        __asm   jl                      lpa_lift0
 
1320
        __asm   dec                     ebx
 
1321
 
 
1322
lpa_lift0:      ;
 
1323
        __asm   test    ebx, ebx
 
1324
        __asm   jle             done_lpa_lift0
 
1325
lpb_lift0:
 
1326
        __asm   mov             eax, dword ptr[esi]
 
1327
        __asm   sub             ebx, 1
 
1328
        __asm   add             eax, dword ptr[esi + ecx ]
 
1329
        __asm   test    eax, eax
 
1330
        __asm   je              skip_slowa_lift0
 
1331
 
 
1332
        __asm   mov             edx, DBL_FIX_D
 
1333
        __asm   imul    edx
 
1334
        __asm   shrd    eax, edx, JPC_FIX_FRACBITS
 
1335
        __asm   add             dword ptr[edi], eax
 
1336
 
 
1337
skip_slowa_lift0:
 
1338
        __asm   add             esi, ecx
 
1339
        __asm   add             edi, ecx
 
1340
        __asm   test    ebx, ebx
 
1341
        __asm   jg              lpb_lift0
 
1342
done_lpa_lift0: ;
 
1343
 
 
1344
        __asm   mov     eax,    hendind
 
1345
        __asm   cmp     eax,    lendind
 
1346
        __asm   jl                      no_3b_lift0
 
1347
        __asm   mov                     eax, dword ptr[esi]
 
1348
        __asm   test            eax, eax
 
1349
        __asm   je                      no_3b_lift0
 
1350
        __asm   mov                     edx, twoalpha_D
 
1351
        __asm   imul            edx
 
1352
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
 
1353
        __asm   add                     dword ptr[edi],eax
 
1354
no_3b_lift0:            ;
 
1355
 
 
1356
 
 
1357
#endif
 
1358
 
 
1359
#if !defined(USE_LF_ASM)
 
1360
                                NNS_LIFT1(      lstartptr, 
 
1361
                                                        lstartind, 
 
1362
                                                        lendind,
 
1363
                                                        hstartptr, 
 
1364
                                                        hstartind, 
 
1365
                                                        hendind, 
 
1366
                                                        intrastep,
 
1367
                                                        DBL_FIX_E
 
1368
                                                );
 
1369
#else
 
1370
 
 
1371
        __asm   mov     esi,    lstartptr
 
1372
        __asm   mov     edi,    hstartptr
 
1373
        __asm   mov     eax,    lstartind
 
1374
        __asm   mov ebx,        lendind
 
1375
        __asm   sub ebx,        eax
 
1376
 
 
1377
        __asm   mov     eax,    hstartind
 
1378
        __asm   cmp     eax,    lstartind
 
1379
        __asm   jl                      no_1a
 
1380
        
 
1381
        __asm   mov                     eax, [edi]
 
1382
        __asm   test            eax, eax
 
1383
        __asm   je                      skip_slow1
 
1384
        __asm   mov                     edx, twoalpha_E
 
1385
        __asm   imul            edx
 
1386
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
 
1387
        __asm   add                     dword ptr[esi], eax
 
1388
skip_slow1:
 
1389
 
 
1390
        __asm   add                     esi, ecx
 
1391
        __asm   sub                     ebx, 1
 
1392
no_1a:
 
1393
        __asm   mov     eax,    lendind
 
1394
        __asm   cmp     eax,    hendind
 
1395
        __asm   jle                     lpa
 
1396
        __asm   sub                     ebx, 1
 
1397
 
 
1398
lpa:
 
1399
        __asm   test    ebx, ebx
 
1400
        __asm   jle             done_lpa
 
1401
lpaa:
 
1402
        __asm   mov             eax, dword ptr[edi]
 
1403
        __asm   sub             ebx, 1
 
1404
        __asm   add             eax, dword ptr[edi + ecx ]
 
1405
        __asm   test    eax, eax
 
1406
        __asm   je              skip_slow
 
1407
 
 
1408
        __asm   mov             edx, DBL_FIX_E
 
1409
        __asm   imul    edx
 
1410
        __asm   shrd    eax, edx, JPC_FIX_FRACBITS
 
1411
        __asm   add             dword ptr[esi], eax
 
1412
 
 
1413
skip_slow:
 
1414
        __asm   add             esi, ecx
 
1415
        __asm   add             edi, ecx
 
1416
        __asm   test    ebx, ebx
 
1417
        __asm   jg              lpaa
 
1418
done_lpa:                                                       ;
 
1419
 
 
1420
        __asm   mov     eax,    lendind
 
1421
        __asm   cmp     eax,    hendind
 
1422
        __asm   jle                     no_3a
 
1423
        __asm   mov                     eax, dword ptr[edi]
 
1424
        __asm   test            eax, eax
 
1425
        __asm   je                      no_3a
 
1426
        __asm   mov                     edx, dword ptr[twoalpha_E]
 
1427
        __asm   imul            edx
 
1428
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
 
1429
        __asm   add                     dword ptr[esi],eax
 
1430
no_3a:          ;
 
1431
#endif
 
1432
 
 
1433
 
 
1434
 
 
1435
#if !defined(USE_LF_ASM)
 
1436
                                NNS_LIFT0(      lstartptr, 
 
1437
                                                        lstartind, 
 
1438
                                                        lendind,
 
1439
                                                        hstartptr, 
 
1440
                                                        hstartind, 
 
1441
                                                        hendind, 
 
1442
                                                        intrastep,
 
1443
                                                        DBL_FIX_F
 
1444
                                                );
 
1445
#else
 
1446
 
 
1447
        __asm   mov     esi,    lstartptr
 
1448
        __asm   mov     edi,    hstartptr
 
1449
        __asm   mov     eax,    hstartind
 
1450
        __asm   mov ebx,        hendind
 
1451
        __asm   sub ebx,        eax
 
1452
 
 
1453
        __asm   mov     eax,    hstartind
 
1454
        __asm   cmp     eax,    lstartind
 
1455
        __asm   jge                     no_1d
 
1456
        
 
1457
        __asm   mov                     eax, [edi]
 
1458
        __asm   test            eax, eax
 
1459
        __asm   je                      skip_slow4
 
1460
        __asm   mov                     edx, twoalpha_F
 
1461
        __asm   imul            edx
 
1462
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
 
1463
        __asm   add                     dword ptr[esi], eax
 
1464
skip_slow4:
 
1465
 
 
1466
        __asm   add                     esi, ecx
 
1467
        __asm   sub                     ebx, 1
 
1468
no_1d:
 
1469
 
 
1470
        __asm   mov     eax,    hendind
 
1471
        __asm   cmp     eax,    lendind
 
1472
        __asm   jl                      lpd
 
1473
        __asm   dec                     ebx
 
1474
 
 
1475
lpd:    ;
 
1476
        __asm   test    ebx, ebx
 
1477
        __asm   jle             done_lpd
 
1478
lpad:
 
1479
        __asm   mov             eax, dword ptr[esi]
 
1480
        __asm   sub             ebx, 1
 
1481
        __asm   add             eax, dword ptr[esi + ecx ]
 
1482
        __asm   test    eax, eax
 
1483
        __asm   je              skip_slowd
 
1484
 
 
1485
        __asm   mov             edx, DBL_FIX_F
 
1486
        __asm   imul    edx
 
1487
        __asm   shrd    eax, edx, JPC_FIX_FRACBITS
 
1488
        __asm   add             dword ptr[edi], eax
 
1489
 
 
1490
skip_slowd:
 
1491
        __asm   add             esi, ecx
 
1492
        __asm   add             edi, ecx
 
1493
        __asm   test    ebx, ebx
 
1494
        __asm   jg              lpad
 
1495
done_lpd:       ;
 
1496
 
 
1497
        __asm   mov     eax,    hendind
 
1498
        __asm   cmp     eax,    lendind
 
1499
        __asm   jl                      no_3d
 
1500
        __asm   mov                     eax, dword ptr[esi]
 
1501
        __asm   test            eax, eax
 
1502
        __asm   je                      no_3d
 
1503
        __asm   mov                     edx, twoalpha_F
 
1504
        __asm   imul            edx
 
1505
        __asm   shrd            eax, edx, JPC_FIX_FRACBITS
 
1506
        __asm   add                     dword ptr[edi],eax
 
1507
no_3d:          ;
 
1508
#endif
 
1509
 
 
1510
 
 
1511
                                jpc_qmfb1d_join(        startptr, 
 
1512
                                                                        startind, 
 
1513
                                                                        endind,
 
1514
                                                                        intrastep, 
 
1515
                                                                        lstartptr, 
 
1516
                                                                        lstartind, 
 
1517
                                                                        lendind,
 
1518
                                                                        hstartptr, 
 
1519
                                                                        hstartind, 
 
1520
                                                                        hendind
 
1521
                                                                );
 
1522
                        } else 
 
1523
                        {
 
1524
#if !defined(USE_LF_ASM)
 
1525
                                if (lstartind == lendind) {
 
1526
                                        *startptr = jpc_fix_asr(*startptr, 1);
 
1527
                                }
 
1528
#endif
 
1529
                        }
 
1530
                        startptr += interstep;
 
1531
                }
 
1532
        } else {
 
1533
                /* The reversible integer-to-integer mode is not supported
 
1534
                  for this transform. */
 
1535
                jas_error(      JAS_ERR_UNSUPPORTED_MODE_JPC_NS_SYNTHESIZE,
 
1536
                                        "JAS_ERR_UNSUPPORTED_MODE_JPC_NS_SYNTHESIZE"
 
1537
                                );
 
1538
        }
 
1539
}
 
1540
 
 
1541
#endif
 
1542
 
 
1543
 
 
1544
/******************************************************************************\
 
1545
*
 
1546
\******************************************************************************/
 
1547
 
 
1548
jpc_qmfb1d_t *jpc_qmfb1d_make(int qmfbid)
 
1549
{
 
1550
        jpc_qmfb1d_t *qmfb;
 
1551
        if (!(qmfb = jpc_qmfb1d_create())) {
 
1552
                return 0;
 
1553
        }
 
1554
        switch (qmfbid) {
 
1555
        case JPC_QMFB1D_FT:
 
1556
                qmfb->ops = &jpc_ft_ops;
 
1557
                break;
 
1558
        case JPC_QMFB1D_NS:
 
1559
                qmfb->ops = &jpc_ns_ops;
 
1560
                break;
 
1561
        default:
 
1562
                jpc_qmfb1d_destroy(qmfb);
 
1563
                return 0;
 
1564
                break;
 
1565
        }
 
1566
        return qmfb;
 
1567
}
 
1568
 
 
1569
static jpc_qmfb1d_t *jpc_qmfb1d_create()
 
1570
{
 
1571
        jpc_qmfb1d_t *qmfb;
 
1572
        if (!(qmfb = jas_malloc(sizeof(jpc_qmfb1d_t)))) {
 
1573
                return 0;
 
1574
        }
 
1575
        qmfb->ops = 0;
 
1576
        return qmfb;
 
1577
}
 
1578
 
 
1579
jpc_qmfb1d_t *jpc_qmfb1d_copy(jpc_qmfb1d_t *qmfb)
 
1580
{
 
1581
        jpc_qmfb1d_t *newqmfb;
 
1582
 
 
1583
        if (!(newqmfb = jpc_qmfb1d_create())) {
 
1584
                return 0;
 
1585
        }
 
1586
        newqmfb->ops = qmfb->ops;
 
1587
        return newqmfb;
 
1588
}
 
1589
 
 
1590
void jpc_qmfb1d_destroy(jpc_qmfb1d_t *qmfb)
 
1591
{
 
1592
        jas_free(qmfb);
 
1593
}
 
1594
 
 
1595
/******************************************************************************\
 
1596
*
 
1597
\******************************************************************************/
 
1598
 
 
1599
void jpc_qmfb1d_getbands(jpc_qmfb1d_t *qmfb, int flags, uint_fast32_t xstart,
 
1600
  uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend, int maxbands,
 
1601
  int *numbandsptr, jpc_qmfb1dband_t *bands)
 
1602
{
 
1603
        int start;
 
1604
        int end;
 
1605
 
 
1606
        assert(maxbands >= 2);
 
1607
 
 
1608
        if (flags & JPC_QMFB1D_VERT) {
 
1609
                start = ystart;
 
1610
                end = yend;
 
1611
        } else {
 
1612
                start = xstart;
 
1613
                end = xend;
 
1614
        }
 
1615
/*      assert(jpc_qmfb1d_getnumchans(qmfb) == 2);      */
 
1616
        assert(start <= end);
 
1617
        bands[0].start = JPC_CEILDIVPOW2(start, 1);
 
1618
        bands[0].end = JPC_CEILDIVPOW2(end, 1);
 
1619
        bands[0].locstart = start;
 
1620
        bands[0].locend = start + bands[0].end - bands[0].start;
 
1621
        bands[1].start = JPC_FLOORDIVPOW2(start, 1);
 
1622
        bands[1].end = JPC_FLOORDIVPOW2(end, 1);
 
1623
        bands[1].locstart = bands[0].locend;
 
1624
        bands[1].locend = bands[1].locstart + bands[1].end - bands[1].start;
 
1625
        assert(bands[1].locend == end);
 
1626
        *numbandsptr = 2;
 
1627
}
 
1628
 
 
1629
/******************************************************************************\
 
1630
*
 
1631
\******************************************************************************/
 
1632
 
 
1633
int jpc_qmfb1d_getnumchans(jpc_qmfb1d_t *qmfb)
 
1634
{
 
1635
        return (*qmfb->ops->getnumchans)(qmfb);
 
1636
}
 
1637
 
 
1638
int jpc_qmfb1d_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
 
1639
{
 
1640
        return (*qmfb->ops->getanalfilters)(qmfb, len, filters);
 
1641
}
 
1642
 
 
1643
int jpc_qmfb1d_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
 
1644
{
 
1645
        return (*qmfb->ops->getsynfilters)(qmfb, len, filters);
 
1646
}
 
1647
 
 
1648
void jpc_qmfb1d_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
 
1649
{
 
1650
        (*qmfb->ops->analyze)(qmfb, flags, x);
 
1651
}
 
1652
 
 
1653
void jpc_qmfb1d_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
 
1654
{
 
1655
        (*qmfb->ops->synthesize)(qmfb, flags, x);
 
1656
}