2
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
4
* Copyright (c) 2001-2003 Michael David Adams.
5
* Copyright (c) 2005-2006 Artifex Software, Inc.
10
/* __START_OF_JASPER_LICENSE__
12
* JasPer License Version 2.0
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
18
* All rights reserved.
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:
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.
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
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.
63
* __END_OF_JASPER_LICENSE__
67
* Quadrature Mirror-Image Filter Bank (QMFB) Library
72
/******************************************************************************\
74
\******************************************************************************/
78
#include "jasper/jas_fix.h"
79
#include "jasper/jas_malloc.h"
80
#include "jasper/jas_math.h"
81
#include "jasper/jas_debug.h"
88
# if defined(_WIN32) && !defined(_WIN64) && ! defined(__BORLANDC__)
89
# define USE_ASM_WIN32
93
/******************************************************************************\
95
\******************************************************************************/
97
static jpc_qmfb1d_t *jpc_qmfb1d_create(void);
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);
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);
111
static void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
114
static void jpc_win32_ns_synthesize( jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
117
/******************************************************************************\
119
\******************************************************************************/
121
jpc_qmfb1dops_t jpc_ft_ops = {
123
jpc_ft_getanalfilters,
124
jpc_ft_getsynfilters,
129
jpc_qmfb1dops_t jpc_ns_ops = {
131
jpc_ns_getanalfilters,
132
jpc_ns_getsynfilters,
135
jpc_win32_ns_synthesize
141
/******************************************************************************\
143
\******************************************************************************/
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)
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];
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)
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];
166
jpc_fix_t splitbuf[bufsize];
168
jpc_fix_t *buf = splitbuf;
173
register jpc_fix_t *ptr;
174
register jpc_fix_t *hptr;
175
register jpc_fix_t *lptr;
180
llen = lendind - lstartind;
181
hlen = hendind - hstartind;
183
#if !defined(HAVE_VLA)
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"
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. */
203
ptr = &startptr[step];
217
/* Copy the appropriate samples into the highpass subband
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);
228
/* Handle the overwritten samples. */
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. */
256
/* Copy the appropriate samples into the highpass subband
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);
267
/* Handle the overwritten samples. */
276
#if !defined(HAVE_VLA)
277
/* If the split buffer was allocated on the heap, free this memory. */
278
if (buf != splitbuf) {
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)
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];
293
jpc_fix_t joinbuf[bufsize];
295
jpc_fix_t *buf = joinbuf;
300
register jpc_fix_t *ptr;
301
register jpc_fix_t *hptr;
302
register jpc_fix_t *lptr;
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"
320
llen = lendind - lstartind;
321
hlen = hendind - hstartind;
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
339
n = hlen - ((llen + 1) >> 1);
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];
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];
378
n = llen - (llen >> 1);
384
/* Copy the appropriate samples into the second phase of
385
the output signal (corresponding to odd indexed
387
ptr = &startptr[step];
404
#if !defined(HAVE_VLA)
405
/* If the join buffer was allocated on the heap, free this memory. */
406
if (buf != joinbuf) {
412
/******************************************************************************\
413
* Code for 5/3 transform.
414
\******************************************************************************/
416
static int jpc_ft_getnumchans(jpc_qmfb1d_t *qmfb)
418
/* Avoid compiler warnings about unused parameters. */
424
static int jpc_ft_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
426
/* Avoid compiler warnings about unused parameters. */
431
jas_error( JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_FT_GETANALFILTERS,
432
"JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_FT_GETANALFILTERS"
437
static int jpc_ft_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
442
/* Avoid compiler warnings about unused parameters. */
448
if (len > 1 || (!len)) {
449
if (!(lf = jas_seq_create(-1, 2))) {
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))) {
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))) {
467
jas_seq_set(lf, 0, jpc_dbltofix(1.0));
468
if (!(hf = jas_seq_create(0, 1))) {
471
jas_seq_set(hf, 0, jpc_dbltofix(2.0));
473
jas_error( JAS_ERR_INVALID_LEN_PARAM_JPC_FT_GETSYNFILTERS,
474
"JAS_ERR_INVALID_LEN_PARAM_JPC_FT_GETSYNFILTERS"
494
#define NFT_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pluseq) \
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); \
504
if ((hendind) >= (lendind)) { \
508
pluseq(*hptr, jpc_fix_asr(jpc_fix_add(*lptr, lptr[(step)]), 1)); \
512
if ((hendind) >= (lendind)) { \
513
pluseq(*hptr, *lptr); \
517
#define NFT_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pluseq) \
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); \
527
if ((lendind) > (hendind)) { \
531
pluseq(*lptr, jpc_fix_asr(jpc_fix_add(*hptr, hptr[(step)]), 2)); \
535
if ((lendind) > (hendind)) { \
536
pluseq(*lptr, *hptr); \
540
#define RFT_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pmeqop) \
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; \
550
if ((hendind) >= (lendind)) { \
554
*hptr pmeqop (*lptr + lptr[(step)]) >> 1; \
558
if ((hendind) >= (lendind)) { \
559
*hptr pmeqop *lptr; \
563
#define RFT_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pmeqop) \
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; \
573
if ((lendind) > (hendind)) { \
577
*lptr pmeqop ((*hptr + hptr[(step)]) + 2) >> 2; \
581
if ((lendind) > (hendind)) { \
582
*lptr pmeqop ((*hptr << 1) + 2) >> 2; \
586
static void jpc_ft_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
591
jpc_fix_t * lstartptr;
594
jpc_fix_t * hstartptr;
601
/* Avoid compiler warnings about unused parameters. */
604
if (flags & JPC_QMFB1D_VERT) {
606
intrastep = jas_seq2d_rowstep(x);
607
numseq = jas_seq2d_width(x);
608
startind = jas_seq2d_ystart(x);
609
endind = jas_seq2d_yend(x);
611
interstep = jas_seq2d_rowstep(x);
613
numseq = jas_seq2d_height(x);
614
startind = jas_seq2d_xstart(x);
615
endind = jas_seq2d_xend(x);
618
assert(startind < endind);
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, +=);
635
if (lstartind == lendind) {
639
startptr += interstep;
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,
653
NFT_LIFT1(lstartptr, lstartind, lendind,
654
hstartptr, hstartind, hendind, intrastep,
657
if (lstartind == lendind) {
658
*startptr = jpc_fix_asl(*startptr, 1);
661
startptr += interstep;
666
static void jpc_ft_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
671
jpc_fix_t *lstartptr;
674
jpc_fix_t *hstartptr;
681
/* Avoid compiler warnings about unused parameters. */
684
if (flags & JPC_QMFB1D_VERT) {
686
intrastep = jas_seq2d_rowstep(x);
687
numseq = jas_seq2d_width(x);
688
startind = jas_seq2d_ystart(x);
689
endind = jas_seq2d_yend(x);
691
interstep = jas_seq2d_rowstep(x);
693
numseq = jas_seq2d_height(x);
694
startind = jas_seq2d_xstart(x);
695
endind = jas_seq2d_xend(x);
698
assert(startind < endind);
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);
715
if (lstartind == lendind) {
719
startptr += interstep;
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,
730
NFT_LIFT0(lstartptr, lstartind, lendind,
731
hstartptr, hstartind, hendind, intrastep,
733
jpc_qmfb1d_join(startptr, startind, endind,
734
intrastep, lstartptr, lstartind, lendind,
735
hstartptr, hstartind, hendind);
737
if (lstartind == lendind) {
738
*startptr = jpc_fix_asr(*startptr, 1);
741
startptr += interstep;
746
/******************************************************************************\
747
* Code for 9/7 transform.
748
\******************************************************************************/
750
static int jpc_ns_getnumchans(jpc_qmfb1d_t *qmfb)
752
/* Avoid compiler warnings about unused parameters. */
758
static int jpc_ns_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
760
/* Avoid compiler warnings about unused parameters. */
765
jas_error( JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_NS_GETANALFILTERS,
766
"JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_NS_GETANALFILTERS"
771
static int jpc_ns_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
776
/* Avoid compiler warnings about unused parameters. */
782
if (len > 1 || (!len)) {
783
if (!(lf = jas_seq_create(-3, 4))) {
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))) {
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))) {
809
jas_seq_set(lf, 0, jpc_dbltofix(1.0));
810
if (!(hf = jas_seq_create(0, 1))) {
813
jas_seq_set(hf, 0, jpc_dbltofix(2.0));
815
jas_error( JAS_ERR_INVALID_LEN_PARAM_JPC_NS_GETSYNFILTERS,
816
"JAS_ERR_INVALID_LEN_PARAM_JPC_NS_GETSYNFILTERS"
836
#define NNS_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \
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))); \
847
if ((hendind) >= (lendind)) { \
851
jpc_fix_pluseq(*hptr, jpc_fix_mul(jpc_fix_add(*lptr, lptr[(step)]), (alpha))); \
855
if ((hendind) >= (lendind)) { \
856
jpc_fix_pluseq(*hptr, jpc_fix_mul(*lptr, (twoalpha))); \
860
#define NNS_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \
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))); \
871
if ((lendind) > (hendind)) { \
875
jpc_fix_pluseq(*lptr, jpc_fix_mul(jpc_fix_add(*hptr, hptr[(step)]), (alpha))); \
879
if ((lendind) > (hendind)) { \
880
jpc_fix_pluseq(*lptr, jpc_fix_mul(*hptr, (twoalpha))); \
884
#define NNS_SCALE(startptr, startind, endind, step, alpha) \
886
register jpc_fix_t *ptr = (startptr); \
887
register int n = (endind) - (startind); \
889
jpc_fix_muleq(*ptr, alpha); \
894
static void jpc_ns_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
899
jpc_fix_t *lstartptr;
902
jpc_fix_t *hstartptr;
909
/* Avoid compiler warnings about unused parameters. */
912
if (flags & JPC_QMFB1D_VERT) {
914
intrastep = jas_seq2d_rowstep(x);
915
numseq = jas_seq2d_width(x);
916
startind = jas_seq2d_ystart(x);
917
endind = jas_seq2d_yend(x);
919
interstep = jas_seq2d_rowstep(x);
921
numseq = jas_seq2d_height(x);
922
startind = jas_seq2d_xstart(x);
923
endind = jas_seq2d_xend(x);
926
assert(startind < endind);
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));
956
if (lstartind == lendind) {
957
*startptr = jpc_fix_asl(*startptr, 1);
961
startptr += interstep;
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"
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)
982
#define twoalpha_C (0xffffe39e)
983
#define twoalpha_D (0xffffc780)
984
#define twoalpha_E (0x00000364)
985
#define twoalpha_F (0x00006582)
992
void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
997
jpc_fix_t *lstartptr;
1000
jpc_fix_t *hstartptr;
1007
/* Avoid compiler warnings about unused parameters. */
1010
if (flags & JPC_QMFB1D_VERT) {
1012
intrastep = jas_seq2d_rowstep(x);
1013
numseq = jas_seq2d_width(x);
1014
startind = jas_seq2d_ystart(x);
1015
endind = jas_seq2d_yend(x);
1017
interstep = jas_seq2d_rowstep(x);
1019
numseq = jas_seq2d_height(x);
1020
startind = jas_seq2d_xstart(x);
1021
endind = jas_seq2d_xend(x);
1024
assert(startind < endind);
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);
1054
if (lstartind == lendind) {
1055
*startptr = jpc_fix_asr(*startptr, 1);
1059
startptr += interstep;
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"
1072
#ifdef USE_ASM_WIN32
1077
void jpc_win32_ns_synthesize( jpc_qmfb1d_t *qmfb,
1082
jpc_fix_t *startptr;
1085
jpc_fix_t *lstartptr;
1088
jpc_fix_t *hstartptr;
1095
/* Avoid compiler warnings about unused parameters. */
1098
if (flags & JPC_QMFB1D_VERT)
1101
intrastep = jas_seq2d_rowstep(x);
1102
numseq = jas_seq2d_width(x);
1103
startind = jas_seq2d_ystart(x);
1104
endind = jas_seq2d_yend(x);
1108
interstep = jas_seq2d_rowstep(x);
1110
numseq = jas_seq2d_height(x);
1111
startind = jas_seq2d_xstart(x);
1112
endind = jas_seq2d_xend(x);
1115
assert(startind < endind);
1117
startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
1119
if (!(flags & JPC_QMFB1D_RITIMODE))
1121
while (numseq-- > 0)
1123
jpc_qmfb1d_setup( startptr,
1135
if (endind - startind > 1)
1137
#if !defined(USE_LF_ASM)
1138
NNS_SCALE( lstartptr,
1146
__asm mov esi, lstartptr
1147
__asm mov eax, lstartind
1148
__asm mov ebx, lendind
1150
__asm mov ecx, intrastep
1155
__asm je skip_scale0
1157
__asm mov eax, [esi]
1160
__asm mov edx, DBL_FIX_A
1162
__asm shrd eax, edx, JPC_FIX_FRACBITS
1163
__asm mov [esi], eax
1172
#if !defined(USE_LF_ASM)
1173
NNS_SCALE( hstartptr,
1181
__asm mov esi, hstartptr
1182
__asm mov eax, hstartind
1183
__asm mov ebx, hendind
1188
__asm je skip_scale1
1190
__asm mov eax, [esi]
1193
__asm mov edx, DBL_FIX_B
1195
__asm shrd eax, edx, JPC_FIX_FRACBITS
1196
__asm mov [esi], eax
1205
#if !defined(USE_LF_ASM)
1206
RA_NNS_LIFT1( lstartptr,
1218
__asm mov esi, lstartptr
1219
__asm mov edi, hstartptr
1220
__asm mov eax, lstartind
1221
__asm mov ebx, lendind
1224
__asm mov eax, hstartind
1225
__asm cmp eax, lstartind
1228
__asm mov eax, [edi]
1230
__asm je skip_slow1C
1231
__asm mov edx, twoalpha_C
1233
__asm shrd eax, edx, JPC_FIX_FRACBITS
1234
__asm add dword ptr[esi], eax
1240
__asm mov eax, lendind
1241
__asm cmp eax, hendind
1249
__asm mov eax, dword ptr[edi]
1251
__asm add eax, dword ptr[edi + ecx ]
1255
__asm mov edx, DBL_FIX_C
1257
__asm shrd eax, edx, JPC_FIX_FRACBITS
1258
__asm add dword ptr[esi], eax
1267
__asm mov eax, lendind
1268
__asm cmp eax, hendind
1270
__asm mov eax, dword ptr[edi]
1273
__asm mov edx, dword ptr[twoalpha_C]
1275
__asm shrd eax, edx, JPC_FIX_FRACBITS
1276
__asm add dword ptr[esi],eax
1282
#if !defined(USE_LF_ASM)
1283
NNS_LIFT0( lstartptr,
1294
__asm mov esi, lstartptr
1295
__asm mov edi, hstartptr
1296
__asm mov eax, hstartind
1297
__asm mov ebx, hendind
1300
__asm mov eax, hstartind
1301
__asm cmp eax, lstartind
1304
__asm mov eax, [edi]
1306
__asm je skip_slow_lift0
1307
__asm mov edx, twoalpha_D
1309
__asm shrd eax, edx, JPC_FIX_FRACBITS
1310
__asm add dword ptr[esi], eax
1317
__asm mov eax, hendind
1318
__asm cmp eax, lendind
1324
__asm jle done_lpa_lift0
1326
__asm mov eax, dword ptr[esi]
1328
__asm add eax, dword ptr[esi + ecx ]
1330
__asm je skip_slowa_lift0
1332
__asm mov edx, DBL_FIX_D
1334
__asm shrd eax, edx, JPC_FIX_FRACBITS
1335
__asm add dword ptr[edi], eax
1344
__asm mov eax, hendind
1345
__asm cmp eax, lendind
1346
__asm jl no_3b_lift0
1347
__asm mov eax, dword ptr[esi]
1349
__asm je no_3b_lift0
1350
__asm mov edx, twoalpha_D
1352
__asm shrd eax, edx, JPC_FIX_FRACBITS
1353
__asm add dword ptr[edi],eax
1359
#if !defined(USE_LF_ASM)
1360
NNS_LIFT1( lstartptr,
1371
__asm mov esi, lstartptr
1372
__asm mov edi, hstartptr
1373
__asm mov eax, lstartind
1374
__asm mov ebx, lendind
1377
__asm mov eax, hstartind
1378
__asm cmp eax, lstartind
1381
__asm mov eax, [edi]
1384
__asm mov edx, twoalpha_E
1386
__asm shrd eax, edx, JPC_FIX_FRACBITS
1387
__asm add dword ptr[esi], eax
1393
__asm mov eax, lendind
1394
__asm cmp eax, hendind
1402
__asm mov eax, dword ptr[edi]
1404
__asm add eax, dword ptr[edi + ecx ]
1408
__asm mov edx, DBL_FIX_E
1410
__asm shrd eax, edx, JPC_FIX_FRACBITS
1411
__asm add dword ptr[esi], eax
1420
__asm mov eax, lendind
1421
__asm cmp eax, hendind
1423
__asm mov eax, dword ptr[edi]
1426
__asm mov edx, dword ptr[twoalpha_E]
1428
__asm shrd eax, edx, JPC_FIX_FRACBITS
1429
__asm add dword ptr[esi],eax
1435
#if !defined(USE_LF_ASM)
1436
NNS_LIFT0( lstartptr,
1447
__asm mov esi, lstartptr
1448
__asm mov edi, hstartptr
1449
__asm mov eax, hstartind
1450
__asm mov ebx, hendind
1453
__asm mov eax, hstartind
1454
__asm cmp eax, lstartind
1457
__asm mov eax, [edi]
1460
__asm mov edx, twoalpha_F
1462
__asm shrd eax, edx, JPC_FIX_FRACBITS
1463
__asm add dword ptr[esi], eax
1470
__asm mov eax, hendind
1471
__asm cmp eax, lendind
1479
__asm mov eax, dword ptr[esi]
1481
__asm add eax, dword ptr[esi + ecx ]
1485
__asm mov edx, DBL_FIX_F
1487
__asm shrd eax, edx, JPC_FIX_FRACBITS
1488
__asm add dword ptr[edi], eax
1497
__asm mov eax, hendind
1498
__asm cmp eax, lendind
1500
__asm mov eax, dword ptr[esi]
1503
__asm mov edx, twoalpha_F
1505
__asm shrd eax, edx, JPC_FIX_FRACBITS
1506
__asm add dword ptr[edi],eax
1511
jpc_qmfb1d_join( startptr,
1524
#if !defined(USE_LF_ASM)
1525
if (lstartind == lendind) {
1526
*startptr = jpc_fix_asr(*startptr, 1);
1530
startptr += interstep;
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"
1544
/******************************************************************************\
1546
\******************************************************************************/
1548
jpc_qmfb1d_t *jpc_qmfb1d_make(int qmfbid)
1551
if (!(qmfb = jpc_qmfb1d_create())) {
1556
qmfb->ops = &jpc_ft_ops;
1559
qmfb->ops = &jpc_ns_ops;
1562
jpc_qmfb1d_destroy(qmfb);
1569
static jpc_qmfb1d_t *jpc_qmfb1d_create()
1572
if (!(qmfb = jas_malloc(sizeof(jpc_qmfb1d_t)))) {
1579
jpc_qmfb1d_t *jpc_qmfb1d_copy(jpc_qmfb1d_t *qmfb)
1581
jpc_qmfb1d_t *newqmfb;
1583
if (!(newqmfb = jpc_qmfb1d_create())) {
1586
newqmfb->ops = qmfb->ops;
1590
void jpc_qmfb1d_destroy(jpc_qmfb1d_t *qmfb)
1595
/******************************************************************************\
1597
\******************************************************************************/
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)
1606
assert(maxbands >= 2);
1608
if (flags & JPC_QMFB1D_VERT) {
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);
1629
/******************************************************************************\
1631
\******************************************************************************/
1633
int jpc_qmfb1d_getnumchans(jpc_qmfb1d_t *qmfb)
1635
return (*qmfb->ops->getnumchans)(qmfb);
1638
int jpc_qmfb1d_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
1640
return (*qmfb->ops->getanalfilters)(qmfb, len, filters);
1643
int jpc_qmfb1d_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
1645
return (*qmfb->ops->getsynfilters)(qmfb, len, filters);
1648
void jpc_qmfb1d_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
1650
(*qmfb->ops->analyze)(qmfb, flags, x);
1653
void jpc_qmfb1d_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
1655
(*qmfb->ops->synthesize)(qmfb, flags, x);
2
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
4
* Copyright (c) 2001-2003 Michael David Adams.
5
* Copyright (c) 2005-2006 Artifex Software, Inc.
10
/* __START_OF_JASPER_LICENSE__
12
* JasPer License Version 2.0
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
18
* All rights reserved.
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:
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.
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
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.
63
* __END_OF_JASPER_LICENSE__
67
* Quadrature Mirror-Image Filter Bank (QMFB) Library
72
/******************************************************************************\
74
\******************************************************************************/
78
#include "jasper/jas_fix.h"
79
#include "jasper/jas_malloc.h"
80
#include "jasper/jas_math.h"
81
#include "jasper/jas_debug.h"
88
# if defined(_MSC_VER) && !defined(_WIN64) && !defined(__BORLANDC__)
93
/******************************************************************************\
95
\******************************************************************************/
97
static jpc_qmfb1d_t *jpc_qmfb1d_create(void);
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);
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);
111
static void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
114
static void jpc_msvc_ns_synthesize( jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x);
117
/******************************************************************************\
119
\******************************************************************************/
121
jpc_qmfb1dops_t jpc_ft_ops = {
123
jpc_ft_getanalfilters,
124
jpc_ft_getsynfilters,
129
jpc_qmfb1dops_t jpc_ns_ops = {
131
jpc_ns_getanalfilters,
132
jpc_ns_getsynfilters,
135
jpc_msvc_ns_synthesize
141
/******************************************************************************\
143
\******************************************************************************/
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)
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];
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)
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];
166
jpc_fix_t splitbuf[bufsize];
168
jpc_fix_t *buf = splitbuf;
173
register jpc_fix_t *ptr;
174
register jpc_fix_t *hptr;
175
register jpc_fix_t *lptr;
180
llen = lendind - lstartind;
181
hlen = hendind - hstartind;
183
#if !defined(HAVE_VLA)
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"
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. */
203
ptr = &startptr[step];
217
/* Copy the appropriate samples into the highpass subband
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);
228
/* Handle the overwritten samples. */
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. */
256
/* Copy the appropriate samples into the highpass subband
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);
267
/* Handle the overwritten samples. */
276
#if !defined(HAVE_VLA)
277
/* If the split buffer was allocated on the heap, free this memory. */
278
if (buf != splitbuf) {
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)
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];
293
jpc_fix_t joinbuf[bufsize];
295
jpc_fix_t *buf = joinbuf;
300
register jpc_fix_t *ptr;
301
register jpc_fix_t *hptr;
302
register jpc_fix_t *lptr;
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"
320
llen = lendind - lstartind;
321
hlen = hendind - hstartind;
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
339
n = hlen - ((llen + 1) >> 1);
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];
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];
378
n = llen - (llen >> 1);
384
/* Copy the appropriate samples into the second phase of
385
the output signal (corresponding to odd indexed
387
ptr = &startptr[step];
404
#if !defined(HAVE_VLA)
405
/* If the join buffer was allocated on the heap, free this memory. */
406
if (buf != joinbuf) {
412
/******************************************************************************\
413
* Code for 5/3 transform.
414
\******************************************************************************/
416
static int jpc_ft_getnumchans(jpc_qmfb1d_t *qmfb)
418
/* Avoid compiler warnings about unused parameters. */
424
static int jpc_ft_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
426
/* Avoid compiler warnings about unused parameters. */
431
jas_error( JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_FT_GETANALFILTERS,
432
"JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_FT_GETANALFILTERS"
437
static int jpc_ft_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
442
/* Avoid compiler warnings about unused parameters. */
448
if (len > 1 || (!len)) {
449
if (!(lf = jas_seq_create(-1, 2))) {
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))) {
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))) {
467
jas_seq_set(lf, 0, jpc_dbltofix(1.0));
468
if (!(hf = jas_seq_create(0, 1))) {
471
jas_seq_set(hf, 0, jpc_dbltofix(2.0));
473
jas_error( JAS_ERR_INVALID_LEN_PARAM_JPC_FT_GETSYNFILTERS,
474
"JAS_ERR_INVALID_LEN_PARAM_JPC_FT_GETSYNFILTERS"
494
#define NFT_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pluseq) \
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); \
504
if ((hendind) >= (lendind)) { \
508
pluseq(*hptr, jpc_fix_asr(jpc_fix_add(*lptr, lptr[(step)]), 1)); \
512
if ((hendind) >= (lendind)) { \
513
pluseq(*hptr, *lptr); \
517
#define NFT_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pluseq) \
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); \
527
if ((lendind) > (hendind)) { \
531
pluseq(*lptr, jpc_fix_asr(jpc_fix_add(*hptr, hptr[(step)]), 2)); \
535
if ((lendind) > (hendind)) { \
536
pluseq(*lptr, *hptr); \
540
#define RFT_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pmeqop) \
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; \
550
if ((hendind) >= (lendind)) { \
554
*hptr pmeqop (*lptr + lptr[(step)]) >> 1; \
558
if ((hendind) >= (lendind)) { \
559
*hptr pmeqop *lptr; \
563
#define RFT_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, pmeqop) \
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; \
573
if ((lendind) > (hendind)) { \
577
*lptr pmeqop ((*hptr + hptr[(step)]) + 2) >> 2; \
581
if ((lendind) > (hendind)) { \
582
*lptr pmeqop ((*hptr << 1) + 2) >> 2; \
586
static void jpc_ft_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
591
jpc_fix_t * lstartptr;
594
jpc_fix_t * hstartptr;
601
/* Avoid compiler warnings about unused parameters. */
604
if (flags & JPC_QMFB1D_VERT) {
606
intrastep = jas_seq2d_rowstep(x);
607
numseq = jas_seq2d_width(x);
608
startind = jas_seq2d_ystart(x);
609
endind = jas_seq2d_yend(x);
611
interstep = jas_seq2d_rowstep(x);
613
numseq = jas_seq2d_height(x);
614
startind = jas_seq2d_xstart(x);
615
endind = jas_seq2d_xend(x);
618
assert(startind < endind);
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, +=);
635
if (lstartind == lendind) {
639
startptr += interstep;
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,
653
NFT_LIFT1(lstartptr, lstartind, lendind,
654
hstartptr, hstartind, hendind, intrastep,
657
if (lstartind == lendind) {
658
*startptr = jpc_fix_asl(*startptr, 1);
661
startptr += interstep;
666
static void jpc_ft_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
671
jpc_fix_t *lstartptr;
674
jpc_fix_t *hstartptr;
681
/* Avoid compiler warnings about unused parameters. */
684
if (flags & JPC_QMFB1D_VERT) {
686
intrastep = jas_seq2d_rowstep(x);
687
numseq = jas_seq2d_width(x);
688
startind = jas_seq2d_ystart(x);
689
endind = jas_seq2d_yend(x);
691
interstep = jas_seq2d_rowstep(x);
693
numseq = jas_seq2d_height(x);
694
startind = jas_seq2d_xstart(x);
695
endind = jas_seq2d_xend(x);
698
assert(startind < endind);
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);
715
if (lstartind == lendind) {
719
startptr += interstep;
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,
730
NFT_LIFT0(lstartptr, lstartind, lendind,
731
hstartptr, hstartind, hendind, intrastep,
733
jpc_qmfb1d_join(startptr, startind, endind,
734
intrastep, lstartptr, lstartind, lendind,
735
hstartptr, hstartind, hendind);
737
if (lstartind == lendind) {
738
*startptr = jpc_fix_asr(*startptr, 1);
741
startptr += interstep;
746
/******************************************************************************\
747
* Code for 9/7 transform.
748
\******************************************************************************/
750
static int jpc_ns_getnumchans(jpc_qmfb1d_t *qmfb)
752
/* Avoid compiler warnings about unused parameters. */
758
static int jpc_ns_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
760
/* Avoid compiler warnings about unused parameters. */
765
jas_error( JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_NS_GETANALFILTERS,
766
"JAS_ERR_INCOMPLETE_STUB_INVOKED_JPC_NS_GETANALFILTERS"
771
static int jpc_ns_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
776
/* Avoid compiler warnings about unused parameters. */
782
if (len > 1 || (!len)) {
783
if (!(lf = jas_seq_create(-3, 4))) {
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))) {
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))) {
809
jas_seq_set(lf, 0, jpc_dbltofix(1.0));
810
if (!(hf = jas_seq_create(0, 1))) {
813
jas_seq_set(hf, 0, jpc_dbltofix(2.0));
815
jas_error( JAS_ERR_INVALID_LEN_PARAM_JPC_NS_GETSYNFILTERS,
816
"JAS_ERR_INVALID_LEN_PARAM_JPC_NS_GETSYNFILTERS"
836
#define NNS_LIFT0(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \
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))); \
847
if ((hendind) >= (lendind)) { \
851
jpc_fix_pluseq(*hptr, jpc_fix_mul(jpc_fix_add(*lptr, lptr[(step)]), (alpha))); \
855
if ((hendind) >= (lendind)) { \
856
jpc_fix_pluseq(*hptr, jpc_fix_mul(*lptr, (twoalpha))); \
860
#define NNS_LIFT1(lstartptr, lstartind, lendind, hstartptr, hstartind, hendind, step, alpha) \
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))); \
871
if ((lendind) > (hendind)) { \
875
jpc_fix_pluseq(*lptr, jpc_fix_mul(jpc_fix_add(*hptr, hptr[(step)]), (alpha))); \
879
if ((lendind) > (hendind)) { \
880
jpc_fix_pluseq(*lptr, jpc_fix_mul(*hptr, (twoalpha))); \
884
#define NNS_SCALE(startptr, startind, endind, step, alpha) \
886
register jpc_fix_t *ptr = (startptr); \
887
register int n = (endind) - (startind); \
889
jpc_fix_muleq(*ptr, alpha); \
894
static void jpc_ns_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
899
jpc_fix_t *lstartptr;
902
jpc_fix_t *hstartptr;
909
/* Avoid compiler warnings about unused parameters. */
912
if (flags & JPC_QMFB1D_VERT) {
914
intrastep = jas_seq2d_rowstep(x);
915
numseq = jas_seq2d_width(x);
916
startind = jas_seq2d_ystart(x);
917
endind = jas_seq2d_yend(x);
919
interstep = jas_seq2d_rowstep(x);
921
numseq = jas_seq2d_height(x);
922
startind = jas_seq2d_xstart(x);
923
endind = jas_seq2d_xend(x);
926
assert(startind < endind);
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));
956
if (lstartind == lendind) {
957
*startptr = jpc_fix_asl(*startptr, 1);
961
startptr += interstep;
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"
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)
982
#define twoalpha_C (0xffffe39e)
983
#define twoalpha_D (0xffffc780)
984
#define twoalpha_E (0x00000364)
985
#define twoalpha_F (0x00006582)
992
void jpc_ns_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
997
jpc_fix_t *lstartptr;
1000
jpc_fix_t *hstartptr;
1007
/* Avoid compiler warnings about unused parameters. */
1010
if (flags & JPC_QMFB1D_VERT) {
1012
intrastep = jas_seq2d_rowstep(x);
1013
numseq = jas_seq2d_width(x);
1014
startind = jas_seq2d_ystart(x);
1015
endind = jas_seq2d_yend(x);
1017
interstep = jas_seq2d_rowstep(x);
1019
numseq = jas_seq2d_height(x);
1020
startind = jas_seq2d_xstart(x);
1021
endind = jas_seq2d_xend(x);
1024
assert(startind < endind);
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);
1054
if (lstartind == lendind) {
1055
*startptr = jpc_fix_asr(*startptr, 1);
1059
startptr += interstep;
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"
1077
void jpc_msvc_ns_synthesize( jpc_qmfb1d_t *qmfb,
1082
jpc_fix_t *startptr;
1085
jpc_fix_t *lstartptr;
1088
jpc_fix_t *hstartptr;
1095
/* Avoid compiler warnings about unused parameters. */
1098
if (flags & JPC_QMFB1D_VERT)
1101
intrastep = jas_seq2d_rowstep(x);
1102
numseq = jas_seq2d_width(x);
1103
startind = jas_seq2d_ystart(x);
1104
endind = jas_seq2d_yend(x);
1108
interstep = jas_seq2d_rowstep(x);
1110
numseq = jas_seq2d_height(x);
1111
startind = jas_seq2d_xstart(x);
1112
endind = jas_seq2d_xend(x);
1115
assert(startind < endind);
1117
startptr = jas_seq2d_getref(x, jas_seq2d_xstart(x), jas_seq2d_ystart(x));
1119
if (!(flags & JPC_QMFB1D_RITIMODE))
1121
while (numseq-- > 0)
1123
jpc_qmfb1d_setup( startptr,
1135
if (endind - startind > 1)
1137
#if !defined(USE_LF_ASM)
1138
NNS_SCALE( lstartptr,
1146
__asm mov esi, lstartptr
1147
__asm mov eax, lstartind
1148
__asm mov ebx, lendind
1150
__asm mov ecx, intrastep
1155
__asm je skip_scale0
1157
__asm mov eax, [esi]
1160
__asm mov edx, DBL_FIX_A
1162
__asm shrd eax, edx, JPC_FIX_FRACBITS
1163
__asm mov [esi], eax
1172
#if !defined(USE_LF_ASM)
1173
NNS_SCALE( hstartptr,
1181
__asm mov esi, hstartptr
1182
__asm mov eax, hstartind
1183
__asm mov ebx, hendind
1188
__asm je skip_scale1
1190
__asm mov eax, [esi]
1193
__asm mov edx, DBL_FIX_B
1195
__asm shrd eax, edx, JPC_FIX_FRACBITS
1196
__asm mov [esi], eax
1205
#if !defined(USE_LF_ASM)
1206
RA_NNS_LIFT1( lstartptr,
1218
__asm mov esi, lstartptr
1219
__asm mov edi, hstartptr
1220
__asm mov eax, lstartind
1221
__asm mov ebx, lendind
1224
__asm mov eax, hstartind
1225
__asm cmp eax, lstartind
1228
__asm mov eax, [edi]
1230
__asm je skip_slow1C
1231
__asm mov edx, twoalpha_C
1233
__asm shrd eax, edx, JPC_FIX_FRACBITS
1234
__asm add dword ptr[esi], eax
1240
__asm mov eax, lendind
1241
__asm cmp eax, hendind
1249
__asm mov eax, dword ptr[edi]
1251
__asm add eax, dword ptr[edi + ecx ]
1255
__asm mov edx, DBL_FIX_C
1257
__asm shrd eax, edx, JPC_FIX_FRACBITS
1258
__asm add dword ptr[esi], eax
1267
__asm mov eax, lendind
1268
__asm cmp eax, hendind
1270
__asm mov eax, dword ptr[edi]
1273
__asm mov edx, dword ptr[twoalpha_C]
1275
__asm shrd eax, edx, JPC_FIX_FRACBITS
1276
__asm add dword ptr[esi],eax
1282
#if !defined(USE_LF_ASM)
1283
NNS_LIFT0( lstartptr,
1294
__asm mov esi, lstartptr
1295
__asm mov edi, hstartptr
1296
__asm mov eax, hstartind
1297
__asm mov ebx, hendind
1300
__asm mov eax, hstartind
1301
__asm cmp eax, lstartind
1304
__asm mov eax, [edi]
1306
__asm je skip_slow_lift0
1307
__asm mov edx, twoalpha_D
1309
__asm shrd eax, edx, JPC_FIX_FRACBITS
1310
__asm add dword ptr[esi], eax
1317
__asm mov eax, hendind
1318
__asm cmp eax, lendind
1324
__asm jle done_lpa_lift0
1326
__asm mov eax, dword ptr[esi]
1328
__asm add eax, dword ptr[esi + ecx ]
1330
__asm je skip_slowa_lift0
1332
__asm mov edx, DBL_FIX_D
1334
__asm shrd eax, edx, JPC_FIX_FRACBITS
1335
__asm add dword ptr[edi], eax
1344
__asm mov eax, hendind
1345
__asm cmp eax, lendind
1346
__asm jl no_3b_lift0
1347
__asm mov eax, dword ptr[esi]
1349
__asm je no_3b_lift0
1350
__asm mov edx, twoalpha_D
1352
__asm shrd eax, edx, JPC_FIX_FRACBITS
1353
__asm add dword ptr[edi],eax
1359
#if !defined(USE_LF_ASM)
1360
NNS_LIFT1( lstartptr,
1371
__asm mov esi, lstartptr
1372
__asm mov edi, hstartptr
1373
__asm mov eax, lstartind
1374
__asm mov ebx, lendind
1377
__asm mov eax, hstartind
1378
__asm cmp eax, lstartind
1381
__asm mov eax, [edi]
1384
__asm mov edx, twoalpha_E
1386
__asm shrd eax, edx, JPC_FIX_FRACBITS
1387
__asm add dword ptr[esi], eax
1393
__asm mov eax, lendind
1394
__asm cmp eax, hendind
1402
__asm mov eax, dword ptr[edi]
1404
__asm add eax, dword ptr[edi + ecx ]
1408
__asm mov edx, DBL_FIX_E
1410
__asm shrd eax, edx, JPC_FIX_FRACBITS
1411
__asm add dword ptr[esi], eax
1420
__asm mov eax, lendind
1421
__asm cmp eax, hendind
1423
__asm mov eax, dword ptr[edi]
1426
__asm mov edx, dword ptr[twoalpha_E]
1428
__asm shrd eax, edx, JPC_FIX_FRACBITS
1429
__asm add dword ptr[esi],eax
1435
#if !defined(USE_LF_ASM)
1436
NNS_LIFT0( lstartptr,
1447
__asm mov esi, lstartptr
1448
__asm mov edi, hstartptr
1449
__asm mov eax, hstartind
1450
__asm mov ebx, hendind
1453
__asm mov eax, hstartind
1454
__asm cmp eax, lstartind
1457
__asm mov eax, [edi]
1460
__asm mov edx, twoalpha_F
1462
__asm shrd eax, edx, JPC_FIX_FRACBITS
1463
__asm add dword ptr[esi], eax
1470
__asm mov eax, hendind
1471
__asm cmp eax, lendind
1479
__asm mov eax, dword ptr[esi]
1481
__asm add eax, dword ptr[esi + ecx ]
1485
__asm mov edx, DBL_FIX_F
1487
__asm shrd eax, edx, JPC_FIX_FRACBITS
1488
__asm add dword ptr[edi], eax
1497
__asm mov eax, hendind
1498
__asm cmp eax, lendind
1500
__asm mov eax, dword ptr[esi]
1503
__asm mov edx, twoalpha_F
1505
__asm shrd eax, edx, JPC_FIX_FRACBITS
1506
__asm add dword ptr[edi],eax
1511
jpc_qmfb1d_join( startptr,
1524
#if !defined(USE_LF_ASM)
1525
if (lstartind == lendind) {
1526
*startptr = jpc_fix_asr(*startptr, 1);
1530
startptr += interstep;
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"
1544
/******************************************************************************\
1546
\******************************************************************************/
1548
jpc_qmfb1d_t *jpc_qmfb1d_make(int qmfbid)
1551
if (!(qmfb = jpc_qmfb1d_create())) {
1556
qmfb->ops = &jpc_ft_ops;
1559
qmfb->ops = &jpc_ns_ops;
1562
jpc_qmfb1d_destroy(qmfb);
1569
static jpc_qmfb1d_t *jpc_qmfb1d_create()
1572
if (!(qmfb = jas_malloc(sizeof(jpc_qmfb1d_t)))) {
1579
jpc_qmfb1d_t *jpc_qmfb1d_copy(jpc_qmfb1d_t *qmfb)
1581
jpc_qmfb1d_t *newqmfb;
1583
if (!(newqmfb = jpc_qmfb1d_create())) {
1586
newqmfb->ops = qmfb->ops;
1590
void jpc_qmfb1d_destroy(jpc_qmfb1d_t *qmfb)
1595
/******************************************************************************\
1597
\******************************************************************************/
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)
1606
assert(maxbands >= 2);
1608
if (flags & JPC_QMFB1D_VERT) {
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);
1629
/******************************************************************************\
1631
\******************************************************************************/
1633
int jpc_qmfb1d_getnumchans(jpc_qmfb1d_t *qmfb)
1635
return (*qmfb->ops->getnumchans)(qmfb);
1638
int jpc_qmfb1d_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
1640
return (*qmfb->ops->getanalfilters)(qmfb, len, filters);
1643
int jpc_qmfb1d_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters)
1645
return (*qmfb->ops->getsynfilters)(qmfb, len, filters);
1648
void jpc_qmfb1d_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
1650
(*qmfb->ops->analyze)(qmfb, flags, x);
1653
void jpc_qmfb1d_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x)
1655
(*qmfb->ops->synthesize)(qmfb, flags, x);