2 * Copyright (c) 1999-2000 Image Power, Inc. and the University of
4 * Copyright (c) 2001-2003 Michael David Adams.
8 /* __START_OF_JASPER_LICENSE__
10 * JasPer License Version 2.0
12 * Copyright (c) 2001-2006 Michael David Adams
13 * Copyright (c) 1999-2000 Image Power, Inc.
14 * Copyright (c) 1999-2000 The University of British Columbia
16 * All rights reserved.
18 * Permission is hereby granted, free of charge, to any person (the
19 * "User") obtaining a copy of this software and associated documentation
20 * files (the "Software"), to deal in the Software without restriction,
21 * including without limitation the rights to use, copy, modify, merge,
22 * publish, distribute, and/or sell copies of the Software, and to permit
23 * persons to whom the Software is furnished to do so, subject to the
24 * following conditions:
26 * 1. The above copyright notices and this permission notice (which
27 * includes the disclaimer below) shall be included in all copies or
28 * substantial portions of the Software.
30 * 2. The name of a copyright holder shall not be used to endorse or
31 * promote products derived from the Software without specific prior
34 * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
35 * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
36 * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
37 * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
38 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
39 * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
40 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
41 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
42 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
43 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
44 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
45 * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
46 * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
47 * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
48 * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
49 * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
50 * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
51 * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
52 * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
53 * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
54 * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
55 * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
56 * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
57 * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
58 * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
59 * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
61 * __END_OF_JASPER_LICENSE__
65 * Quadrature Mirror-Image Filter Bank (QMFB) Library
67 * $Id: jpc_qmfb.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
70 /******************************************************************************\
72 \******************************************************************************/
74 #undef WT_LENONE /* This is not needed due to normalization. */
77 /******************************************************************************\
79 \******************************************************************************/
82 #include "jasper/jas_fix.h"
83 #include "jasper/jas_malloc.h"
84 #include "jasper/jas_math.h"
90 /******************************************************************************\
92 \******************************************************************************/
94 #define QMFB_SPLITBUFSIZE 4096
95 #define QMFB_JOINBUFSIZE 4096
97 int jpc_ft_analyze(jpc_fix_t *a, int xstart, int ystart, int width, int height,
99 int jpc_ft_synthesize(int *a, int xstart, int ystart, int width, int height,
102 int jpc_ns_analyze(jpc_fix_t *a, int xstart, int ystart, int width, int height,
104 int jpc_ns_synthesize(jpc_fix_t *a, int xstart, int ystart, int width,
105 int height, int stride);
107 void jpc_ft_fwdlift_row(jpc_fix_t *a, int numcols, int parity);
108 void jpc_ft_fwdlift_col(jpc_fix_t *a, int numrows, int stride,
110 void jpc_ft_fwdlift_colgrp(jpc_fix_t *a, int numrows, int stride,
112 void jpc_ft_fwdlift_colres(jpc_fix_t *a, int numrows, int numcols,
113 int stride, int parity);
115 void jpc_ft_invlift_row(jpc_fix_t *a, int numcols, int parity);
116 void jpc_ft_invlift_col(jpc_fix_t *a, int numrows, int stride,
118 void jpc_ft_invlift_colgrp(jpc_fix_t *a, int numrows, int stride,
120 void jpc_ft_invlift_colres(jpc_fix_t *a, int numrows, int numcols,
121 int stride, int parity);
123 void jpc_ns_fwdlift_row(jpc_fix_t *a, int numcols, int parity);
124 void jpc_ns_fwdlift_colgrp(jpc_fix_t *a, int numrows, int stride, int parity);
125 void jpc_ns_fwdlift_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
127 void jpc_ns_invlift_row(jpc_fix_t *a, int numcols, int parity);
128 void jpc_ns_invlift_colgrp(jpc_fix_t *a, int numrows, int stride, int parity);
129 void jpc_ns_invlift_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
132 void jpc_qmfb_split_row(jpc_fix_t *a, int numcols, int parity);
133 void jpc_qmfb_split_col(jpc_fix_t *a, int numrows, int stride, int parity);
134 void jpc_qmfb_split_colgrp(jpc_fix_t *a, int numrows, int stride, int parity);
135 void jpc_qmfb_split_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
138 void jpc_qmfb_join_row(jpc_fix_t *a, int numcols, int parity);
139 void jpc_qmfb_join_col(jpc_fix_t *a, int numrows, int stride, int parity);
140 void jpc_qmfb_join_colgrp(jpc_fix_t *a, int numrows, int stride, int parity);
141 void jpc_qmfb_join_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
144 double jpc_ft_lpenergywts[32] = {
158 104.5115624560829133,
159 147.8016689469569656,
160 209.0231247296646018,
161 295.6033378293900000,
162 418.0462494347059419,
163 591.2066756503630813,
164 836.0924988714708661,
166 836.0924988714708661,
167 836.0924988714708661,
168 836.0924988714708661,
169 836.0924988714708661,
170 836.0924988714708661,
171 836.0924988714708661,
172 836.0924988714708661,
173 836.0924988714708661,
174 836.0924988714708661,
175 836.0924988714708661,
176 836.0924988714708661,
180 double jpc_ft_hpenergywts[32] = {
196 110.8512517317256822,
197 156.7673435548526868,
198 221.7025033739244293,
199 313.5346870787551552,
200 443.4050067351659550,
202 443.4050067351659550,
203 443.4050067351659550,
204 443.4050067351659550,
205 443.4050067351659550,
206 443.4050067351659550,
207 443.4050067351659550,
208 443.4050067351659550,
209 443.4050067351659550,
210 443.4050067351659550,
211 443.4050067351659550,
212 443.4050067351659550,
216 double jpc_ns_lpenergywts[32] = {
230 131.8290408510004283,
231 186.4344176300625691,
232 263.6580819564562148,
233 372.8688353500955373,
234 527.3161639447193920,
235 745.7376707114038936,
236 1054.6323278917823245,
237 /* approximations follow */
238 1054.6323278917823245,
239 1054.6323278917823245,
240 1054.6323278917823245,
241 1054.6323278917823245,
242 1054.6323278917823245,
243 1054.6323278917823245,
244 1054.6323278917823245,
245 1054.6323278917823245,
246 1054.6323278917823245,
247 1054.6323278917823245,
248 1054.6323278917823245,
249 1054.6323278917823245
252 double jpc_ns_hpenergywts[32] = {
266 133.6139330736999113,
267 188.9586372358249378,
268 267.2278678461869390,
269 377.9172750722391356,
270 534.4557359047058753,
271 755.8345502191498326,
272 1068.9114718353569060,
273 /* approximations follow */
274 1068.9114718353569060,
275 1068.9114718353569060,
276 1068.9114718353569060,
277 1068.9114718353569060,
278 1068.9114718353569060,
279 1068.9114718353569060,
280 1068.9114718353569060,
281 1068.9114718353569060,
282 1068.9114718353569060,
283 1068.9114718353569060,
284 1068.9114718353569060
287 jpc_qmfb2d_t jpc_ft_qmfb2d = {
294 jpc_qmfb2d_t jpc_ns_qmfb2d = {
301 /******************************************************************************\
303 \******************************************************************************/
305 void jpc_qmfb_split_row(jpc_fix_t *a, int numcols, int parity)
308 int bufsize = JPC_CEILDIVPOW2(numcols, 1);
309 #if !defined(HAVE_VLA)
310 jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE];
312 jpc_fix_t splitbuf[bufsize];
314 jpc_fix_t *buf = splitbuf;
315 register jpc_fix_t *srcptr;
316 register jpc_fix_t *dstptr;
321 #if !defined(HAVE_VLA)
323 if (bufsize > QMFB_SPLITBUFSIZE) {
324 if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
325 /* We have no choice but to commit suicide in this case. */
332 hstartcol = (numcols + 1 - parity) >> 1;
333 m = (parity) ? hstartcol : (numcols - hstartcol);
334 /* Save the samples destined for the highpass channel. */
337 srcptr = &a[1 - parity];
343 /* Copy the appropriate samples into the lowpass channel. */
344 dstptr = &a[1 - parity];
345 srcptr = &a[2 - parity];
346 n = numcols - m - (!parity);
352 /* Copy the saved samples into the highpass channel. */
353 dstptr = &a[hstartcol];
363 #if !defined(HAVE_VLA)
364 /* If the split buffer was allocated on the heap, free this memory. */
365 if (buf != splitbuf) {
372 void jpc_qmfb_split_col(jpc_fix_t *a, int numrows, int stride,
376 int bufsize = JPC_CEILDIVPOW2(numrows, 1);
377 #if !defined(HAVE_VLA)
378 jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE];
380 jpc_fix_t splitbuf[bufsize];
382 jpc_fix_t *buf = splitbuf;
383 register jpc_fix_t *srcptr;
384 register jpc_fix_t *dstptr;
389 #if !defined(HAVE_VLA)
391 if (bufsize > QMFB_SPLITBUFSIZE) {
392 if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
393 /* We have no choice but to commit suicide in this case. */
400 hstartcol = (numrows + 1 - parity) >> 1;
401 m = (parity) ? hstartcol : (numrows - hstartcol);
402 /* Save the samples destined for the highpass channel. */
405 srcptr = &a[(1 - parity) * stride];
409 srcptr += stride << 1;
411 /* Copy the appropriate samples into the lowpass channel. */
412 dstptr = &a[(1 - parity) * stride];
413 srcptr = &a[(2 - parity) * stride];
414 n = numrows - m - (!parity);
418 srcptr += stride << 1;
420 /* Copy the saved samples into the highpass channel. */
421 dstptr = &a[hstartcol * stride];
431 #if !defined(HAVE_VLA)
432 /* If the split buffer was allocated on the heap, free this memory. */
433 if (buf != splitbuf) {
440 void jpc_qmfb_split_colgrp(jpc_fix_t *a, int numrows, int stride,
444 int bufsize = JPC_CEILDIVPOW2(numrows, 1);
445 #if !defined(HAVE_VLA)
446 jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE * JPC_QMFB_COLGRPSIZE];
448 jpc_fix_t splitbuf[bufsize * JPC_QMFB_COLGRPSIZE];
450 jpc_fix_t *buf = splitbuf;
453 register jpc_fix_t *srcptr2;
454 register jpc_fix_t *dstptr2;
460 #if !defined(HAVE_VLA)
462 if (bufsize > QMFB_SPLITBUFSIZE) {
463 if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
464 /* We have no choice but to commit suicide in this case. */
471 hstartcol = (numrows + 1 - parity) >> 1;
472 m = (parity) ? hstartcol : (numrows - hstartcol);
473 /* Save the samples destined for the highpass channel. */
476 srcptr = &a[(1 - parity) * stride];
480 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
485 dstptr += JPC_QMFB_COLGRPSIZE;
486 srcptr += stride << 1;
488 /* Copy the appropriate samples into the lowpass channel. */
489 dstptr = &a[(1 - parity) * stride];
490 srcptr = &a[(2 - parity) * stride];
491 n = numrows - m - (!parity);
495 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
501 srcptr += stride << 1;
503 /* Copy the saved samples into the highpass channel. */
504 dstptr = &a[hstartcol * stride];
510 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
516 srcptr += JPC_QMFB_COLGRPSIZE;
520 #if !defined(HAVE_VLA)
521 /* If the split buffer was allocated on the heap, free this memory. */
522 if (buf != splitbuf) {
529 void jpc_qmfb_split_colres(jpc_fix_t *a, int numrows, int numcols,
530 int stride, int parity)
533 int bufsize = JPC_CEILDIVPOW2(numrows, 1);
534 #if !defined(HAVE_VLA)
535 jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE * JPC_QMFB_COLGRPSIZE];
537 jpc_fix_t splitbuf[bufsize * numcols];
539 jpc_fix_t *buf = splitbuf;
542 register jpc_fix_t *srcptr2;
543 register jpc_fix_t *dstptr2;
549 #if !defined(HAVE_VLA)
551 if (bufsize > QMFB_SPLITBUFSIZE) {
552 if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
553 /* We have no choice but to commit suicide in this case. */
560 hstartcol = (numrows + 1 - parity) >> 1;
561 m = (parity) ? hstartcol : (numrows - hstartcol);
562 /* Save the samples destined for the highpass channel. */
565 srcptr = &a[(1 - parity) * stride];
569 for (i = 0; i < numcols; ++i) {
575 srcptr += stride << 1;
577 /* Copy the appropriate samples into the lowpass channel. */
578 dstptr = &a[(1 - parity) * stride];
579 srcptr = &a[(2 - parity) * stride];
580 n = numrows - m - (!parity);
584 for (i = 0; i < numcols; ++i) {
590 srcptr += stride << 1;
592 /* Copy the saved samples into the highpass channel. */
593 dstptr = &a[hstartcol * stride];
599 for (i = 0; i < numcols; ++i) {
609 #if !defined(HAVE_VLA)
610 /* If the split buffer was allocated on the heap, free this memory. */
611 if (buf != splitbuf) {
618 void jpc_qmfb_join_row(jpc_fix_t *a, int numcols, int parity)
621 int bufsize = JPC_CEILDIVPOW2(numcols, 1);
622 #if !defined(HAVE_VLA)
623 jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
625 jpc_fix_t joinbuf[bufsize];
627 jpc_fix_t *buf = joinbuf;
628 register jpc_fix_t *srcptr;
629 register jpc_fix_t *dstptr;
633 #if !defined(HAVE_VLA)
634 /* Allocate memory for the join buffer from the heap. */
635 if (bufsize > QMFB_JOINBUFSIZE) {
636 if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
637 /* We have no choice but to commit suicide. */
643 hstartcol = (numcols + 1 - parity) >> 1;
645 /* Save the samples from the lowpass channel. */
654 /* Copy the samples from the highpass channel into place. */
655 srcptr = &a[hstartcol];
656 dstptr = &a[1 - parity];
657 n = numcols - hstartcol;
663 /* Copy the samples from the lowpass channel into place. */
673 #if !defined(HAVE_VLA)
674 /* If the join buffer was allocated on the heap, free this memory. */
675 if (buf != joinbuf) {
682 void jpc_qmfb_join_col(jpc_fix_t *a, int numrows, int stride,
686 int bufsize = JPC_CEILDIVPOW2(numrows, 1);
687 #if !defined(HAVE_VLA)
688 jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
690 jpc_fix_t joinbuf[bufsize];
692 jpc_fix_t *buf = joinbuf;
693 register jpc_fix_t *srcptr;
694 register jpc_fix_t *dstptr;
698 #if !defined(HAVE_VLA)
699 /* Allocate memory for the join buffer from the heap. */
700 if (bufsize > QMFB_JOINBUFSIZE) {
701 if (!(buf = jas_malloc(bufsize * sizeof(jpc_fix_t)))) {
702 /* We have no choice but to commit suicide. */
708 hstartcol = (numrows + 1 - parity) >> 1;
710 /* Save the samples from the lowpass channel. */
719 /* Copy the samples from the highpass channel into place. */
720 srcptr = &a[hstartcol * stride];
721 dstptr = &a[(1 - parity) * stride];
722 n = numrows - hstartcol;
725 dstptr += 2 * stride;
728 /* Copy the samples from the lowpass channel into place. */
730 dstptr = &a[parity * stride];
734 dstptr += 2 * stride;
738 #if !defined(HAVE_VLA)
739 /* If the join buffer was allocated on the heap, free this memory. */
740 if (buf != joinbuf) {
747 void jpc_qmfb_join_colgrp(jpc_fix_t *a, int numrows, int stride,
751 int bufsize = JPC_CEILDIVPOW2(numrows, 1);
752 #if !defined(HAVE_VLA)
753 jpc_fix_t joinbuf[QMFB_JOINBUFSIZE * JPC_QMFB_COLGRPSIZE];
755 jpc_fix_t joinbuf[bufsize * JPC_QMFB_COLGRPSIZE];
757 jpc_fix_t *buf = joinbuf;
760 register jpc_fix_t *srcptr2;
761 register jpc_fix_t *dstptr2;
766 #if !defined(HAVE_VLA)
767 /* Allocate memory for the join buffer from the heap. */
768 if (bufsize > QMFB_JOINBUFSIZE) {
769 if (!(buf = jas_malloc(bufsize * JPC_QMFB_COLGRPSIZE * sizeof(jpc_fix_t)))) {
770 /* We have no choice but to commit suicide. */
776 hstartcol = (numrows + 1 - parity) >> 1;
778 /* Save the samples from the lowpass channel. */
785 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
791 dstptr += JPC_QMFB_COLGRPSIZE;
793 /* Copy the samples from the highpass channel into place. */
794 srcptr = &a[hstartcol * stride];
795 dstptr = &a[(1 - parity) * stride];
796 n = numrows - hstartcol;
800 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
805 dstptr += 2 * stride;
808 /* Copy the samples from the lowpass channel into place. */
810 dstptr = &a[parity * stride];
815 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
820 dstptr += 2 * stride;
821 srcptr += JPC_QMFB_COLGRPSIZE;
824 #if !defined(HAVE_VLA)
825 /* If the join buffer was allocated on the heap, free this memory. */
826 if (buf != joinbuf) {
833 void jpc_qmfb_join_colres(jpc_fix_t *a, int numrows, int numcols,
834 int stride, int parity)
837 int bufsize = JPC_CEILDIVPOW2(numrows, 1);
838 #if !defined(HAVE_VLA)
839 jpc_fix_t joinbuf[QMFB_JOINBUFSIZE * JPC_QMFB_COLGRPSIZE];
841 jpc_fix_t joinbuf[bufsize * numcols];
843 jpc_fix_t *buf = joinbuf;
846 register jpc_fix_t *srcptr2;
847 register jpc_fix_t *dstptr2;
852 #if !defined(HAVE_VLA)
853 /* Allocate memory for the join buffer from the heap. */
854 if (bufsize > QMFB_JOINBUFSIZE) {
855 if (!(buf = jas_malloc(bufsize * numcols * sizeof(jpc_fix_t)))) {
856 /* We have no choice but to commit suicide. */
862 hstartcol = (numrows + 1 - parity) >> 1;
864 /* Save the samples from the lowpass channel. */
871 for (i = 0; i < numcols; ++i) {
879 /* Copy the samples from the highpass channel into place. */
880 srcptr = &a[hstartcol * stride];
881 dstptr = &a[(1 - parity) * stride];
882 n = numrows - hstartcol;
886 for (i = 0; i < numcols; ++i) {
891 dstptr += 2 * stride;
894 /* Copy the samples from the lowpass channel into place. */
896 dstptr = &a[parity * stride];
901 for (i = 0; i < numcols; ++i) {
906 dstptr += 2 * stride;
910 #if !defined(HAVE_VLA)
911 /* If the join buffer was allocated on the heap, free this memory. */
912 if (buf != joinbuf) {
919 /******************************************************************************\
921 \******************************************************************************/
923 void jpc_ft_fwdlift_row(jpc_fix_t *a, int numcols, int parity)
926 register jpc_fix_t *lptr;
927 register jpc_fix_t *hptr;
931 llen = (numcols + 1 - parity) >> 1;
935 /* Apply the first lifting step. */
942 n = numcols - llen - parity - (parity == (numcols & 1));
944 hptr[0] -= (lptr[0] + lptr[1]) >> 1;
948 if (parity == (numcols & 1)) {
952 /* Apply the second lifting step. */
956 lptr[0] += (hptr[0] + 1) >> 1;
959 n = llen - (!parity) - (parity != (numcols & 1));
961 lptr[0] += (hptr[0] + hptr[1] + 2) >> 2;
965 if (parity != (numcols & 1)) {
966 lptr[0] += (hptr[0] + 1) >> 1;
980 void jpc_ft_fwdlift_col(jpc_fix_t *a, int numrows, int stride, int parity)
986 register jpc_fix_t *lptr2;
987 register jpc_fix_t *hptr2;
993 llen = (numrows + 1 - parity) >> 1;
997 /* Apply the first lifting step. */
999 hptr = &a[llen * stride];
1004 n = numrows - llen - parity - (parity == (numrows & 1));
1006 hptr[0] -= (lptr[0] + lptr[stride]) >> 1;
1010 if (parity == (numrows & 1)) {
1014 /* Apply the second lifting step. */
1016 hptr = &a[llen * stride];
1018 lptr[0] += (hptr[0] + 1) >> 1;
1021 n = llen - (!parity) - (parity != (numrows & 1));
1023 lptr[0] += (hptr[0] + hptr[stride] + 2) >> 2;
1027 if (parity != (numrows & 1)) {
1028 lptr[0] += (hptr[0] + 1) >> 1;
1042 void jpc_ft_fwdlift_colgrp(jpc_fix_t *a, int numrows, int stride, int parity)
1047 register jpc_fix_t *lptr2;
1048 register jpc_fix_t *hptr2;
1053 llen = (numrows + 1 - parity) >> 1;
1057 /* Apply the first lifting step. */
1059 hptr = &a[llen * stride];
1063 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1064 hptr2[0] -= lptr2[0];
1070 n = numrows - llen - parity - (parity == (numrows & 1));
1074 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1075 hptr2[0] -= (lptr2[0] + lptr2[stride]) >> 1;
1082 if (parity == (numrows & 1)) {
1085 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1086 hptr2[0] -= lptr2[0];
1092 /* Apply the second lifting step. */
1094 hptr = &a[llen * stride];
1098 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1099 lptr2[0] += (hptr2[0] + 1) >> 1;
1105 n = llen - (!parity) - (parity != (numrows & 1));
1109 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1110 lptr2[0] += (hptr2[0] + hptr2[stride] + 2) >> 2;
1117 if (parity != (numrows & 1)) {
1120 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1121 lptr2[0] += (hptr2[0] + 1) >> 1;
1131 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1141 void jpc_ft_fwdlift_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
1147 register jpc_fix_t *lptr2;
1148 register jpc_fix_t *hptr2;
1153 llen = (numrows + 1 - parity) >> 1;
1157 /* Apply the first lifting step. */
1159 hptr = &a[llen * stride];
1163 for (i = 0; i < numcols; ++i) {
1164 hptr2[0] -= lptr2[0];
1170 n = numrows - llen - parity - (parity == (numrows & 1));
1174 for (i = 0; i < numcols; ++i) {
1175 hptr2[0] -= (lptr2[0] + lptr2[stride]) >> 1;
1182 if (parity == (numrows & 1)) {
1185 for (i = 0; i < numcols; ++i) {
1186 hptr2[0] -= lptr2[0];
1192 /* Apply the second lifting step. */
1194 hptr = &a[llen * stride];
1198 for (i = 0; i < numcols; ++i) {
1199 lptr2[0] += (hptr2[0] + 1) >> 1;
1205 n = llen - (!parity) - (parity != (numrows & 1));
1209 for (i = 0; i < numcols; ++i) {
1210 lptr2[0] += (hptr2[0] + hptr2[stride] + 2) >> 2;
1217 if (parity != (numrows & 1)) {
1220 for (i = 0; i < numcols; ++i) {
1221 lptr2[0] += (hptr2[0] + 1) >> 1;
1231 for (i = 0; i < numcols; ++i) {
1241 void jpc_ft_invlift_row(jpc_fix_t *a, int numcols, int parity)
1244 register jpc_fix_t *lptr;
1245 register jpc_fix_t *hptr;
1249 llen = (numcols + 1 - parity) >> 1;
1253 /* Apply the first lifting step. */
1257 lptr[0] -= (hptr[0] + 1) >> 1;
1260 n = llen - (!parity) - (parity != (numcols & 1));
1262 lptr[0] -= (hptr[0] + hptr[1] + 2) >> 2;
1266 if (parity != (numcols & 1)) {
1267 lptr[0] -= (hptr[0] + 1) >> 1;
1270 /* Apply the second lifting step. */
1277 n = numcols - llen - parity - (parity == (numcols & 1));
1279 hptr[0] += (lptr[0] + lptr[1]) >> 1;
1283 if (parity == (numcols & 1)) {
1298 void jpc_ft_invlift_col(jpc_fix_t *a, int numrows, int stride, int parity)
1304 register jpc_fix_t *lptr2;
1305 register jpc_fix_t *hptr2;
1311 llen = (numrows + 1 - parity) >> 1;
1315 /* Apply the first lifting step. */
1317 hptr = &a[llen * stride];
1319 lptr[0] -= (hptr[0] + 1) >> 1;
1322 n = llen - (!parity) - (parity != (numrows & 1));
1324 lptr[0] -= (hptr[0] + hptr[stride] + 2) >> 2;
1328 if (parity != (numrows & 1)) {
1329 lptr[0] -= (hptr[0] + 1) >> 1;
1332 /* Apply the second lifting step. */
1334 hptr = &a[llen * stride];
1339 n = numrows - llen - parity - (parity == (numrows & 1));
1341 hptr[0] += (lptr[0] + lptr[stride]) >> 1;
1345 if (parity == (numrows & 1)) {
1360 void jpc_ft_invlift_colgrp(jpc_fix_t *a, int numrows, int stride, int parity)
1365 register jpc_fix_t *lptr2;
1366 register jpc_fix_t *hptr2;
1371 llen = (numrows + 1 - parity) >> 1;
1375 /* Apply the first lifting step. */
1377 hptr = &a[llen * stride];
1381 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1382 lptr2[0] -= (hptr2[0] + 1) >> 1;
1388 n = llen - (!parity) - (parity != (numrows & 1));
1392 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1393 lptr2[0] -= (hptr2[0] + hptr2[stride] + 2) >> 2;
1400 if (parity != (numrows & 1)) {
1403 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1404 lptr2[0] -= (hptr2[0] + 1) >> 1;
1410 /* Apply the second lifting step. */
1412 hptr = &a[llen * stride];
1416 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1417 hptr2[0] += lptr2[0];
1423 n = numrows - llen - parity - (parity == (numrows & 1));
1427 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1428 hptr2[0] += (lptr2[0] + lptr2[stride]) >> 1;
1435 if (parity == (numrows & 1)) {
1438 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1439 hptr2[0] += lptr2[0];
1449 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1459 void jpc_ft_invlift_colres(jpc_fix_t *a, int numrows, int numcols, int stride,
1465 register jpc_fix_t *lptr2;
1466 register jpc_fix_t *hptr2;
1471 llen = (numrows + 1 - parity) >> 1;
1475 /* Apply the first lifting step. */
1477 hptr = &a[llen * stride];
1481 for (i = 0; i < numcols; ++i) {
1482 lptr2[0] -= (hptr2[0] + 1) >> 1;
1488 n = llen - (!parity) - (parity != (numrows & 1));
1492 for (i = 0; i < numcols; ++i) {
1493 lptr2[0] -= (hptr2[0] + hptr2[stride] + 2) >> 2;
1500 if (parity != (numrows & 1)) {
1503 for (i = 0; i < numcols; ++i) {
1504 lptr2[0] -= (hptr2[0] + 1) >> 1;
1510 /* Apply the second lifting step. */
1512 hptr = &a[llen * stride];
1516 for (i = 0; i < numcols; ++i) {
1517 hptr2[0] += lptr2[0];
1523 n = numrows - llen - parity - (parity == (numrows & 1));
1527 for (i = 0; i < numcols; ++i) {
1528 hptr2[0] += (lptr2[0] + lptr2[stride]) >> 1;
1535 if (parity == (numrows & 1)) {
1538 for (i = 0; i < numcols; ++i) {
1539 hptr2[0] += lptr2[0];
1549 for (i = 0; i < numcols; ++i) {
1559 int jpc_ft_analyze(jpc_fix_t *a, int xstart, int ystart, int width, int height,
1562 int numrows = height;
1563 int numcols = width;
1564 int rowparity = ystart & 1;
1565 int colparity = xstart & 1;
1567 jpc_fix_t *startptr;
1570 maxcols = (numcols / JPC_QMFB_COLGRPSIZE) * JPC_QMFB_COLGRPSIZE;
1572 for (i = 0; i < maxcols; i += JPC_QMFB_COLGRPSIZE) {
1573 jpc_qmfb_split_colgrp(startptr, numrows, stride, rowparity);
1574 jpc_ft_fwdlift_colgrp(startptr, numrows, stride, rowparity);
1575 startptr += JPC_QMFB_COLGRPSIZE;
1577 if (maxcols < numcols) {
1578 jpc_qmfb_split_colres(startptr, numrows, numcols - maxcols, stride,
1580 jpc_ft_fwdlift_colres(startptr, numrows, numcols - maxcols, stride,
1585 for (i = 0; i < numrows; ++i) {
1586 jpc_qmfb_split_row(startptr, numcols, colparity);
1587 jpc_ft_fwdlift_row(startptr, numcols, colparity);
1595 int jpc_ft_synthesize(int *a, int xstart, int ystart, int width, int height,
1598 int numrows = height;
1599 int numcols = width;
1600 int rowparity = ystart & 1;
1601 int colparity = xstart & 1;
1604 jpc_fix_t *startptr;
1608 for (i = 0; i < numrows; ++i) {
1609 jpc_ft_invlift_row(startptr, numcols, colparity);
1610 jpc_qmfb_join_row(startptr, numcols, colparity);
1614 maxcols = (numcols / JPC_QMFB_COLGRPSIZE) * JPC_QMFB_COLGRPSIZE;
1616 for (i = 0; i < maxcols; i += JPC_QMFB_COLGRPSIZE) {
1617 jpc_ft_invlift_colgrp(startptr, numrows, stride, rowparity);
1618 jpc_qmfb_join_colgrp(startptr, numrows, stride, rowparity);
1619 startptr += JPC_QMFB_COLGRPSIZE;
1621 if (maxcols < numcols) {
1622 jpc_ft_invlift_colres(startptr, numrows, numcols - maxcols, stride,
1624 jpc_qmfb_join_colres(startptr, numrows, numcols - maxcols, stride,
1632 /******************************************************************************\
1634 \******************************************************************************/
1636 #define ALPHA (-1.586134342059924)
1637 #define BETA (-0.052980118572961)
1638 #define GAMMA (0.882911075530934)
1639 #define DELTA (0.443506852043971)
1640 #define LGAIN (1.0 / 1.23017410558578)
1641 #define HGAIN (1.0 / 1.62578613134411)
1643 void jpc_ns_fwdlift_row(jpc_fix_t *a, int numcols, int parity)
1646 register jpc_fix_t *lptr;
1647 register jpc_fix_t *hptr;
1651 llen = (numcols + 1 - parity) >> 1;
1655 /* Apply the first lifting step. */
1659 jpc_fix_pluseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
1663 n = numcols - llen - parity - (parity == (numcols & 1));
1665 jpc_fix_pluseq(hptr[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
1666 jpc_fix_add(lptr[0], lptr[1])));
1670 if (parity == (numcols & 1)) {
1671 jpc_fix_pluseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
1675 /* Apply the second lifting step. */
1679 jpc_fix_pluseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
1683 n = llen - (!parity) - (parity != (numcols & 1));
1685 jpc_fix_pluseq(lptr[0], jpc_fix_mul(jpc_dbltofix(BETA),
1686 jpc_fix_add(hptr[0], hptr[1])));
1690 if (parity != (numcols & 1)) {
1691 jpc_fix_pluseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
1695 /* Apply the third lifting step. */
1699 jpc_fix_pluseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
1703 n = numcols - llen - parity - (parity == (numcols & 1));
1705 jpc_fix_pluseq(hptr[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
1706 jpc_fix_add(lptr[0], lptr[1])));
1710 if (parity == (numcols & 1)) {
1711 jpc_fix_pluseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
1715 /* Apply the fourth lifting step. */
1719 jpc_fix_pluseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
1723 n = llen - (!parity) - (parity != (numcols & 1));
1725 jpc_fix_pluseq(lptr[0], jpc_fix_mul(jpc_dbltofix(DELTA),
1726 jpc_fix_add(hptr[0], hptr[1])));
1730 if (parity != (numcols & 1)) {
1731 jpc_fix_pluseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
1735 /* Apply the scaling step. */
1736 #if defined(WT_DOSCALE)
1740 lptr[0] = jpc_fix_mul(lptr[0], jpc_dbltofix(LGAIN));
1746 hptr[0] = jpc_fix_mul(hptr[0], jpc_dbltofix(HGAIN));
1753 #if defined(WT_LENONE)
1764 void jpc_ns_fwdlift_colgrp(jpc_fix_t *a, int numrows, int stride,
1770 register jpc_fix_t *lptr2;
1771 register jpc_fix_t *hptr2;
1776 llen = (numrows + 1 - parity) >> 1;
1780 /* Apply the first lifting step. */
1782 hptr = &a[llen * stride];
1786 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1787 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
1794 n = numrows - llen - parity - (parity == (numrows & 1));
1798 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1799 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
1800 jpc_fix_add(lptr2[0], lptr2[stride])));
1807 if (parity == (numrows & 1)) {
1810 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1811 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
1818 /* Apply the second lifting step. */
1820 hptr = &a[llen * stride];
1824 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1825 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
1832 n = llen - (!parity) - (parity != (numrows & 1));
1836 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1837 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(BETA),
1838 jpc_fix_add(hptr2[0], hptr2[stride])));
1845 if (parity != (numrows & 1)) {
1848 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1849 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
1856 /* Apply the third lifting step. */
1858 hptr = &a[llen * stride];
1862 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1863 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
1870 n = numrows - llen - parity - (parity == (numrows & 1));
1874 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1875 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
1876 jpc_fix_add(lptr2[0], lptr2[stride])));
1883 if (parity == (numrows & 1)) {
1886 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1887 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
1894 /* Apply the fourth lifting step. */
1896 hptr = &a[llen * stride];
1900 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1901 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
1908 n = llen - (!parity) - (parity != (numrows & 1));
1912 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1913 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(DELTA),
1914 jpc_fix_add(hptr2[0], hptr2[stride])));
1921 if (parity != (numrows & 1)) {
1924 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1925 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
1932 /* Apply the scaling step. */
1933 #if defined(WT_DOSCALE)
1938 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1939 lptr2[0] = jpc_fix_mul(lptr2[0], jpc_dbltofix(LGAIN));
1944 hptr = &a[llen * stride];
1948 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1949 hptr2[0] = jpc_fix_mul(hptr2[0], jpc_dbltofix(HGAIN));
1958 #if defined(WT_LENONE)
1961 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
1972 void jpc_ns_fwdlift_colres(jpc_fix_t *a, int numrows, int numcols,
1973 int stride, int parity)
1978 register jpc_fix_t *lptr2;
1979 register jpc_fix_t *hptr2;
1984 llen = (numrows + 1 - parity) >> 1;
1988 /* Apply the first lifting step. */
1990 hptr = &a[llen * stride];
1994 for (i = 0; i < numcols; ++i) {
1995 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
2002 n = numrows - llen - parity - (parity == (numrows & 1));
2006 for (i = 0; i < numcols; ++i) {
2007 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
2008 jpc_fix_add(lptr2[0], lptr2[stride])));
2015 if (parity == (numrows & 1)) {
2018 for (i = 0; i < numcols; ++i) {
2019 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
2026 /* Apply the second lifting step. */
2028 hptr = &a[llen * stride];
2032 for (i = 0; i < numcols; ++i) {
2033 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
2040 n = llen - (!parity) - (parity != (numrows & 1));
2044 for (i = 0; i < numcols; ++i) {
2045 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(BETA),
2046 jpc_fix_add(hptr2[0], hptr2[stride])));
2053 if (parity != (numrows & 1)) {
2056 for (i = 0; i < numcols; ++i) {
2057 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
2064 /* Apply the third lifting step. */
2066 hptr = &a[llen * stride];
2070 for (i = 0; i < numcols; ++i) {
2071 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
2078 n = numrows - llen - parity - (parity == (numrows & 1));
2082 for (i = 0; i < numcols; ++i) {
2083 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
2084 jpc_fix_add(lptr2[0], lptr2[stride])));
2091 if (parity == (numrows & 1)) {
2094 for (i = 0; i < numcols; ++i) {
2095 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
2102 /* Apply the fourth lifting step. */
2104 hptr = &a[llen * stride];
2108 for (i = 0; i < numcols; ++i) {
2109 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
2116 n = llen - (!parity) - (parity != (numrows & 1));
2120 for (i = 0; i < numcols; ++i) {
2121 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(DELTA),
2122 jpc_fix_add(hptr2[0], hptr2[stride])));
2129 if (parity != (numrows & 1)) {
2132 for (i = 0; i < numcols; ++i) {
2133 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
2140 /* Apply the scaling step. */
2141 #if defined(WT_DOSCALE)
2146 for (i = 0; i < numcols; ++i) {
2147 lptr2[0] = jpc_fix_mul(lptr2[0], jpc_dbltofix(LGAIN));
2152 hptr = &a[llen * stride];
2156 for (i = 0; i < numcols; ++i) {
2157 hptr2[0] = jpc_fix_mul(hptr2[0], jpc_dbltofix(HGAIN));
2166 #if defined(WT_LENONE)
2169 for (i = 0; i < numcols; ++i) {
2180 void jpc_ns_fwdlift_col(jpc_fix_t *a, int numrows, int stride,
2186 register jpc_fix_t *lptr2;
2187 register jpc_fix_t *hptr2;
2191 llen = (numrows + 1 - parity) >> 1;
2195 /* Apply the first lifting step. */
2197 hptr = &a[llen * stride];
2201 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
2207 n = numrows - llen - parity - (parity == (numrows & 1));
2211 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
2212 jpc_fix_add(lptr2[0], lptr2[stride])));
2218 if (parity == (numrows & 1)) {
2221 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
2227 /* Apply the second lifting step. */
2229 hptr = &a[llen * stride];
2233 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
2239 n = llen - (!parity) - (parity != (numrows & 1));
2243 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(BETA),
2244 jpc_fix_add(hptr2[0], hptr2[stride])));
2250 if (parity != (numrows & 1)) {
2253 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
2259 /* Apply the third lifting step. */
2261 hptr = &a[llen * stride];
2265 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
2271 n = numrows - llen - parity - (parity == (numrows & 1));
2275 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
2276 jpc_fix_add(lptr2[0], lptr2[stride])));
2282 if (parity == (numrows & 1)) {
2285 jpc_fix_pluseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
2291 /* Apply the fourth lifting step. */
2293 hptr = &a[llen * stride];
2297 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
2303 n = llen - (!parity) - (parity != (numrows & 1));
2307 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(DELTA),
2308 jpc_fix_add(hptr2[0], hptr2[stride])));
2314 if (parity != (numrows & 1)) {
2317 jpc_fix_pluseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
2323 /* Apply the scaling step. */
2324 #if defined(WT_DOSCALE)
2329 lptr2[0] = jpc_fix_mul(lptr2[0], jpc_dbltofix(LGAIN));
2333 hptr = &a[llen * stride];
2337 hptr2[0] = jpc_fix_mul(hptr2[0], jpc_dbltofix(HGAIN));
2345 #if defined(WT_LENONE)
2357 void jpc_ns_invlift_row(jpc_fix_t *a, int numcols, int parity)
2360 register jpc_fix_t *lptr;
2361 register jpc_fix_t *hptr;
2365 llen = (numcols + 1 - parity) >> 1;
2369 /* Apply the scaling step. */
2370 #if defined(WT_DOSCALE)
2374 lptr[0] = jpc_fix_mul(lptr[0], jpc_dbltofix(1.0 / LGAIN));
2380 hptr[0] = jpc_fix_mul(hptr[0], jpc_dbltofix(1.0 / HGAIN));
2385 /* Apply the first lifting step. */
2389 jpc_fix_minuseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
2393 n = llen - (!parity) - (parity != (numcols & 1));
2395 jpc_fix_minuseq(lptr[0], jpc_fix_mul(jpc_dbltofix(DELTA),
2396 jpc_fix_add(hptr[0], hptr[1])));
2400 if (parity != (numcols & 1)) {
2401 jpc_fix_minuseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * DELTA),
2405 /* Apply the second lifting step. */
2409 jpc_fix_minuseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
2413 n = numcols - llen - parity - (parity == (numcols & 1));
2415 jpc_fix_minuseq(hptr[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
2416 jpc_fix_add(lptr[0], lptr[1])));
2420 if (parity == (numcols & 1)) {
2421 jpc_fix_minuseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * GAMMA),
2425 /* Apply the third lifting step. */
2429 jpc_fix_minuseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
2433 n = llen - (!parity) - (parity != (numcols & 1));
2435 jpc_fix_minuseq(lptr[0], jpc_fix_mul(jpc_dbltofix(BETA),
2436 jpc_fix_add(hptr[0], hptr[1])));
2440 if (parity != (numcols & 1)) {
2441 jpc_fix_minuseq(lptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
2445 /* Apply the fourth lifting step. */
2449 jpc_fix_minuseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
2453 n = numcols - llen - parity - (parity == (numcols & 1));
2455 jpc_fix_minuseq(hptr[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
2456 jpc_fix_add(lptr[0], lptr[1])));
2460 if (parity == (numcols & 1)) {
2461 jpc_fix_minuseq(hptr[0], jpc_fix_mul(jpc_dbltofix(2.0 * ALPHA),
2467 #if defined(WT_LENONE)
2478 void jpc_ns_invlift_colgrp(jpc_fix_t *a, int numrows, int stride,
2484 register jpc_fix_t *lptr2;
2485 register jpc_fix_t *hptr2;
2490 llen = (numrows + 1 - parity) >> 1;
2494 /* Apply the scaling step. */
2495 #if defined(WT_DOSCALE)
2500 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2501 lptr2[0] = jpc_fix_mul(lptr2[0], jpc_dbltofix(1.0 / LGAIN));
2506 hptr = &a[llen * stride];
2510 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2511 hptr2[0] = jpc_fix_mul(hptr2[0], jpc_dbltofix(1.0 / HGAIN));
2518 /* Apply the first lifting step. */
2520 hptr = &a[llen * stride];
2524 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2525 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2532 n = llen - (!parity) - (parity != (numrows & 1));
2536 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2537 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(DELTA),
2538 jpc_fix_add(hptr2[0], hptr2[stride])));
2545 if (parity != (numrows & 1)) {
2548 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2549 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2556 /* Apply the second lifting step. */
2558 hptr = &a[llen * stride];
2562 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2563 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2570 n = numrows - llen - parity - (parity == (numrows & 1));
2574 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2575 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
2576 jpc_fix_add(lptr2[0], lptr2[stride])));
2583 if (parity == (numrows & 1)) {
2586 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2587 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2594 /* Apply the third lifting step. */
2596 hptr = &a[llen * stride];
2600 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2601 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
2608 n = llen - (!parity) - (parity != (numrows & 1));
2612 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2613 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(BETA),
2614 jpc_fix_add(hptr2[0], hptr2[stride])));
2621 if (parity != (numrows & 1)) {
2624 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2625 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
2632 /* Apply the fourth lifting step. */
2634 hptr = &a[llen * stride];
2638 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2639 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2646 n = numrows - llen - parity - (parity == (numrows & 1));
2650 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2651 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
2652 jpc_fix_add(lptr2[0], lptr2[stride])));
2659 if (parity == (numrows & 1)) {
2662 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2663 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2672 #if defined(WT_LENONE)
2675 for (i = 0; i < JPC_QMFB_COLGRPSIZE; ++i) {
2686 void jpc_ns_invlift_colres(jpc_fix_t *a, int numrows, int numcols,
2687 int stride, int parity)
2692 register jpc_fix_t *lptr2;
2693 register jpc_fix_t *hptr2;
2698 llen = (numrows + 1 - parity) >> 1;
2702 /* Apply the scaling step. */
2703 #if defined(WT_DOSCALE)
2708 for (i = 0; i < numcols; ++i) {
2709 lptr2[0] = jpc_fix_mul(lptr2[0], jpc_dbltofix(1.0 / LGAIN));
2714 hptr = &a[llen * stride];
2718 for (i = 0; i < numcols; ++i) {
2719 hptr2[0] = jpc_fix_mul(hptr2[0], jpc_dbltofix(1.0 / HGAIN));
2726 /* Apply the first lifting step. */
2728 hptr = &a[llen * stride];
2732 for (i = 0; i < numcols; ++i) {
2733 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2740 n = llen - (!parity) - (parity != (numrows & 1));
2744 for (i = 0; i < numcols; ++i) {
2745 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(DELTA),
2746 jpc_fix_add(hptr2[0], hptr2[stride])));
2753 if (parity != (numrows & 1)) {
2756 for (i = 0; i < numcols; ++i) {
2757 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2764 /* Apply the second lifting step. */
2766 hptr = &a[llen * stride];
2770 for (i = 0; i < numcols; ++i) {
2771 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2778 n = numrows - llen - parity - (parity == (numrows & 1));
2782 for (i = 0; i < numcols; ++i) {
2783 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
2784 jpc_fix_add(lptr2[0], lptr2[stride])));
2791 if (parity == (numrows & 1)) {
2794 for (i = 0; i < numcols; ++i) {
2795 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2802 /* Apply the third lifting step. */
2804 hptr = &a[llen * stride];
2808 for (i = 0; i < numcols; ++i) {
2809 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
2816 n = llen - (!parity) - (parity != (numrows & 1));
2820 for (i = 0; i < numcols; ++i) {
2821 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(BETA),
2822 jpc_fix_add(hptr2[0], hptr2[stride])));
2829 if (parity != (numrows & 1)) {
2832 for (i = 0; i < numcols; ++i) {
2833 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
2840 /* Apply the fourth lifting step. */
2842 hptr = &a[llen * stride];
2846 for (i = 0; i < numcols; ++i) {
2847 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2854 n = numrows - llen - parity - (parity == (numrows & 1));
2858 for (i = 0; i < numcols; ++i) {
2859 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
2860 jpc_fix_add(lptr2[0], lptr2[stride])));
2867 if (parity == (numrows & 1)) {
2870 for (i = 0; i < numcols; ++i) {
2871 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2880 #if defined(WT_LENONE)
2883 for (i = 0; i < numcols; ++i) {
2894 void jpc_ns_invlift_col(jpc_fix_t *a, int numrows, int stride,
2900 register jpc_fix_t *lptr2;
2901 register jpc_fix_t *hptr2;
2905 llen = (numrows + 1 - parity) >> 1;
2909 /* Apply the scaling step. */
2910 #if defined(WT_DOSCALE)
2915 lptr2[0] = jpc_fix_mul(lptr2[0], jpc_dbltofix(1.0 / LGAIN));
2919 hptr = &a[llen * stride];
2923 hptr2[0] = jpc_fix_mul(hptr2[0], jpc_dbltofix(1.0 / HGAIN));
2929 /* Apply the first lifting step. */
2931 hptr = &a[llen * stride];
2935 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2941 n = llen - (!parity) - (parity != (numrows & 1));
2945 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(DELTA),
2946 jpc_fix_add(hptr2[0], hptr2[stride])));
2952 if (parity != (numrows & 1)) {
2955 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2961 /* Apply the second lifting step. */
2963 hptr = &a[llen * stride];
2967 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2973 n = numrows - llen - parity - (parity == (numrows & 1));
2977 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(GAMMA),
2978 jpc_fix_add(lptr2[0], lptr2[stride])));
2984 if (parity == (numrows & 1)) {
2987 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
2993 /* Apply the third lifting step. */
2995 hptr = &a[llen * stride];
2999 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
3005 n = llen - (!parity) - (parity != (numrows & 1));
3009 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(BETA),
3010 jpc_fix_add(hptr2[0], hptr2[stride])));
3016 if (parity != (numrows & 1)) {
3019 jpc_fix_minuseq(lptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 * BETA),
3025 /* Apply the fourth lifting step. */
3027 hptr = &a[llen * stride];
3031 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
3037 n = numrows - llen - parity - (parity == (numrows & 1));
3041 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(ALPHA),
3042 jpc_fix_add(lptr2[0], lptr2[stride])));
3048 if (parity == (numrows & 1)) {
3051 jpc_fix_minuseq(hptr2[0], jpc_fix_mul(jpc_dbltofix(2.0 *
3059 #if defined(WT_LENONE)
3071 int jpc_ns_analyze(jpc_fix_t *a, int xstart, int ystart, int width, int height,
3075 int numrows = height;
3076 int numcols = width;
3077 int rowparity = ystart & 1;
3078 int colparity = xstart & 1;
3080 jpc_fix_t *startptr;
3083 maxcols = (numcols / JPC_QMFB_COLGRPSIZE) * JPC_QMFB_COLGRPSIZE;
3085 for (i = 0; i < maxcols; i += JPC_QMFB_COLGRPSIZE) {
3086 jpc_qmfb_split_colgrp(startptr, numrows, stride, rowparity);
3087 jpc_ns_fwdlift_colgrp(startptr, numrows, stride, rowparity);
3088 startptr += JPC_QMFB_COLGRPSIZE;
3090 if (maxcols < numcols) {
3091 jpc_qmfb_split_colres(startptr, numrows, numcols - maxcols, stride,
3093 jpc_ns_fwdlift_colres(startptr, numrows, numcols - maxcols, stride,
3098 for (i = 0; i < numrows; ++i) {
3099 jpc_qmfb_split_row(startptr, numcols, colparity);
3100 jpc_ns_fwdlift_row(startptr, numcols, colparity);
3108 int jpc_ns_synthesize(jpc_fix_t *a, int xstart, int ystart, int width,
3109 int height, int stride)
3112 int numrows = height;
3113 int numcols = width;
3114 int rowparity = ystart & 1;
3115 int colparity = xstart & 1;
3117 jpc_fix_t *startptr;
3121 for (i = 0; i < numrows; ++i) {
3122 jpc_ns_invlift_row(startptr, numcols, colparity);
3123 jpc_qmfb_join_row(startptr, numcols, colparity);
3127 maxcols = (numcols / JPC_QMFB_COLGRPSIZE) * JPC_QMFB_COLGRPSIZE;
3129 for (i = 0; i < maxcols; i += JPC_QMFB_COLGRPSIZE) {
3130 jpc_ns_invlift_colgrp(startptr, numrows, stride, rowparity);
3131 jpc_qmfb_join_colgrp(startptr, numrows, stride, rowparity);
3132 startptr += JPC_QMFB_COLGRPSIZE;
3134 if (maxcols < numcols) {
3135 jpc_ns_invlift_colres(startptr, numrows, numcols - maxcols, stride,
3137 jpc_qmfb_join_colres(startptr, numrows, numcols - maxcols, stride,